annotate utils.c @ 294:6091b76cfc2a libavformat

added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
author bellard
date Wed, 29 Oct 2003 14:25:27 +0000
parents 62cec412a186
children 2833c2311b66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * Various utilities for ffmpeg system
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 AVInputFormat *first_iformat;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 AVOutputFormat *first_oformat;
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
23 AVImageFormat *first_image_format;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 void av_register_input_format(AVInputFormat *format)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 AVInputFormat **p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 p = &first_iformat;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 while (*p != NULL) p = &(*p)->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 *p = format;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 format->next = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 void av_register_output_format(AVOutputFormat *format)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 AVOutputFormat **p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 p = &first_oformat;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 while (*p != NULL) p = &(*p)->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 *p = format;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 format->next = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 int match_ext(const char *filename, const char *extensions)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 const char *ext, *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 char ext1[32], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 ext = strrchr(filename, '.');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 if (ext) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 ext++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 p = extensions;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 q = ext1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 while (*p != '\0' && *p != ',')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 *q++ = *p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 if (!strcasecmp(ext1, ext))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 if (*p == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 AVOutputFormat *guess_format(const char *short_name, const char *filename,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 const char *mime_type)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 AVOutputFormat *fmt, *fmt_found;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 int score_max, score;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
73 /* specific test for image sequences */
21
3d2d2f8725f9 jpeg detection fix - fixed imagepipe output
bellard
parents: 20
diff changeset
74 if (!short_name && filename &&
3d2d2f8725f9 jpeg detection fix - fixed imagepipe output
bellard
parents: 20
diff changeset
75 filename_number_test(filename) >= 0 &&
3d2d2f8725f9 jpeg detection fix - fixed imagepipe output
bellard
parents: 20
diff changeset
76 guess_image_format(filename)) {
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
77 return guess_format("image", NULL, NULL);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
78 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
79
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 /* find the proper file type */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 fmt_found = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 score_max = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 fmt = first_oformat;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 while (fmt != NULL) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 score = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 if (fmt->name && short_name && !strcmp(fmt->name, short_name))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 score += 100;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 if (fmt->mime_type && mime_type && !strcmp(fmt->mime_type, mime_type))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 score += 10;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 if (filename && fmt->extensions &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 match_ext(filename, fmt->extensions)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 score += 5;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 if (score > score_max) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 score_max = score;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 fmt_found = fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 fmt = fmt->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 return fmt_found;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 AVOutputFormat *guess_stream_format(const char *short_name, const char *filename,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 const char *mime_type)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 AVOutputFormat *fmt = guess_format(short_name, filename, mime_type);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 if (fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 AVOutputFormat *stream_fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 char stream_format_name[64];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 snprintf(stream_format_name, sizeof(stream_format_name), "%s_stream", fmt->name);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 stream_fmt = guess_format(stream_format_name, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 if (stream_fmt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 fmt = stream_fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 return fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 AVInputFormat *av_find_input_format(const char *short_name)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 AVInputFormat *fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 for(fmt = first_iformat; fmt != NULL; fmt = fmt->next) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 if (!strcmp(fmt->name, short_name))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 return fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 /* memory handling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 /**
53
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
135 * Default packet destructor
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
136 */
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
137 static void av_destruct_packet(AVPacket *pkt)
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
138 {
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
139 av_free(pkt->data);
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
140 pkt->data = NULL; pkt->size = 0;
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
141 }
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
142
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
143 /**
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 * Allocate the payload of a packet and intialized its fields to default values.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 * @param pkt packet
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 * @param size wanted payload size
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 * @return 0 if OK. AVERROR_xxx otherwise.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 int av_new_packet(AVPacket *pkt, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 {
53
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
152 void *data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
153 if (!data)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 return AVERROR_NOMEM;
53
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
155 memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156
53
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
157 av_init_packet(pkt);
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
158 pkt->data = data;
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
159 pkt->size = size;
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
160 pkt->destruct = av_destruct_packet;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 /* fifo handling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 int fifo_init(FifoBuffer *f, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 f->buffer = av_malloc(size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 if (!f->buffer)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 f->end = f->buffer + size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 f->wptr = f->rptr = f->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 void fifo_free(FifoBuffer *f)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 av_free(f->buffer);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
181 int fifo_size(FifoBuffer *f, uint8_t *rptr)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 int size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 if (f->wptr >= rptr) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 size = f->wptr - rptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 size = (f->end - rptr) + (f->wptr - f->buffer);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 return size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 /* get data from the fifo (return -1 if not enough data) */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
194 int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
196 uint8_t *rptr = *rptr_ptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 int size, len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 if (f->wptr >= rptr) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 size = f->wptr - rptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 size = (f->end - rptr) + (f->wptr - f->buffer);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 if (size < buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 while (buf_size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 len = f->end - rptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 if (len > buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 len = buf_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 memcpy(buf, rptr, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 rptr += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 if (rptr >= f->end)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 rptr = f->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 buf_size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 *rptr_ptr = rptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
222 void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 int len;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
225 uint8_t *wptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 wptr = *wptr_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 len = f->end - wptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 if (len > size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 len = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 memcpy(wptr, buf, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 wptr += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 if (wptr >= f->end)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 wptr = f->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 *wptr_ptr = wptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 int filename_number_test(const char *filename)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 char buf[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 return get_frame_filename(buf, sizeof(buf), filename, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 /* guess file format */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 AVInputFormat *fmt1, *fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 int score, score_max;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 fmt = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 score_max = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 for(fmt1 = first_iformat; fmt1 != NULL; fmt1 = fmt1->next) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 if (!is_opened && !(fmt1->flags & AVFMT_NOFILE))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 score = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 if (fmt1->read_probe) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 score = fmt1->read_probe(pd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 } else if (fmt1->extensions) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 if (match_ext(pd->filename, fmt1->extensions)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 score = 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 if (score > score_max) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 score_max = score;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 fmt = fmt1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 return fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 /************************************************************/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 /* input media file */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
277 /**
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
278 * open a media file from an IO stream. 'fmt' must be specified.
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
279 */
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
280 int av_open_input_stream(AVFormatContext **ic_ptr,
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
281 ByteIOContext *pb, const char *filename,
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
282 AVInputFormat *fmt, AVFormatParameters *ap)
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
283 {
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
284 int err;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
285 AVFormatContext *ic;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
286
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
287 ic = av_mallocz(sizeof(AVFormatContext));
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
288 if (!ic) {
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
289 err = AVERROR_NOMEM;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
290 goto fail;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
291 }
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
292 ic->iformat = fmt;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
293 if (pb)
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
294 ic->pb = *pb;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
295 ic->duration = AV_NOPTS_VALUE;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
296 ic->start_time = AV_NOPTS_VALUE;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
297 pstrcpy(ic->filename, sizeof(ic->filename), filename);
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
298
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
299 /* allocate private data */
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
300 if (fmt->priv_data_size > 0) {
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
301 ic->priv_data = av_mallocz(fmt->priv_data_size);
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
302 if (!ic->priv_data) {
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
303 err = AVERROR_NOMEM;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
304 goto fail;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
305 }
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
306 } else {
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
307 ic->priv_data = NULL;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
308 }
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
309
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
310 /* default pts settings is MPEG like */
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
311 av_set_pts_info(ic, 33, 1, 90000);
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
312
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
313 err = ic->iformat->read_header(ic, ap);
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
314 if (err < 0)
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
315 goto fail;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
316 *ic_ptr = ic;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
317 return 0;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
318 fail:
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
319 if (ic) {
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
320 av_freep(&ic->priv_data);
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
321 }
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
322 av_free(ic);
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
323 *ic_ptr = NULL;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
324 return err;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
325 }
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
326
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 #define PROBE_BUF_SIZE 2048
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 * Open a media file as input. The codec are not opened. Only the file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 * header (if present) is read.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 * @param ic_ptr the opened media file handle is put here
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 * @param filename filename to open.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 * @param fmt if non NULL, force the file format to use
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 * @param buf_size optional buffer size (zero if default is OK)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 * @param ap additionnal parameters needed when opening the file (NULL if default)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 * @return 0 if OK. AVERROR_xxx otherwise.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 AVInputFormat *fmt,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 int buf_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 {
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
345 int err, must_open_file, file_opened;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
346 uint8_t buf[PROBE_BUF_SIZE];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 AVProbeData probe_data, *pd = &probe_data;
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
348 ByteIOContext pb1, *pb = &pb1;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
349
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
350 file_opened = 0;
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
351 pd->filename = "";
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
352 if (filename)
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
353 pd->filename = filename;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 pd->buf = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 pd->buf_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 if (!fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 /* guess format if no file can be opened */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 fmt = av_probe_input_format(pd, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361
172
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
362 /* do not open file if the format does not need it. XXX: specific
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
363 hack needed to handle RTSP/TCP */
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
364 must_open_file = 1;
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
365 if (fmt && (fmt->flags & AVFMT_NOFILE)) {
172
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
366 must_open_file = 0;
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
367 }
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
368
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
369 if (!fmt || must_open_file) {
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
370 /* if no file needed do not try to open one */
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
371 if (url_fopen(pb, filename, URL_RDONLY) < 0) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 err = AVERROR_IO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 }
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
375 file_opened = 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 if (buf_size > 0) {
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
377 url_setbufsize(pb, buf_size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 if (!fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 /* read probe data */
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
381 pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
382 url_fseek(pb, 0, SEEK_SET);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 /* guess file format */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387 if (!fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 fmt = av_probe_input_format(pd, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 /* if still no format found, error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 if (!fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 err = AVERROR_NOFMT;
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
394 goto fail;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 /* XXX: suppress this hack for redirectors */
22
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
398 #ifdef CONFIG_NETWORK
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 if (fmt == &redir_demux) {
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
400 err = redir_open(ic_ptr, pb);
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
401 url_fclose(pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 return err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 }
11
932b59c66c60 mingw patch by (Bill Eldridge <bill at rfa dot org>)
michaelni
parents: 9
diff changeset
404 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
406 /* check filename in case of an image number is expected */
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
407 if (fmt->flags & AVFMT_NEEDNUMBER) {
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
408 if (filename_number_test(filename) < 0) {
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
409 err = AVERROR_NUMEXPECTED;
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
410 goto fail;
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
411 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
412 }
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
413 err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap);
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
414 if (err)
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
415 goto fail;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 fail:
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
418 if (file_opened)
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
419 url_fclose(pb);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 *ic_ptr = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 return err;
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
422
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
425 /*******************************************************/
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
426
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 /**
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
428 * Read a packet from a media file. Use it only for low level file
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
429 * reading. It is almost always better to use av_read_frame().
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
430 *
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 * @param pkt is filled
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
433 * @return 0 if OK. AVERROR_xxx if error.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 int av_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 AVPacketList *pktl;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 pktl = s->packet_buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 if (pktl) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 /* read packet from packet buffer, if there is data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 *pkt = pktl->pkt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 s->packet_buffer = pktl->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 av_free(pktl);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 return s->iformat->read_packet(s, pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
451 /*******************************************************/
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
452
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
453 /* return TRUE if the stream has accurate timings for at least one component */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
454 static int av_has_timings(AVFormatContext *ic)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
455 {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
456 int i;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
457 AVStream *st;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
458
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
459 for(i = 0;i < ic->nb_streams; i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
460 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
461 if (st->start_time != AV_NOPTS_VALUE &&
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
462 st->duration != AV_NOPTS_VALUE)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
463 return 1;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
464 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
465 return 0;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
466 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
467
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
468 /* estimate the stream timings from the one of each components. Also
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
469 compute the global bitrate if possible */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
470 static void av_update_stream_timings(AVFormatContext *ic)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
471 {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
472 int64_t start_time, end_time, end_time1;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
473 int i;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
474 AVStream *st;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
475
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
476 start_time = MAXINT64;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
477 end_time = MININT64;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
478 for(i = 0;i < ic->nb_streams; i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
479 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
480 if (st->start_time != AV_NOPTS_VALUE) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
481 if (st->start_time < start_time)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
482 start_time = st->start_time;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
483 if (st->duration != AV_NOPTS_VALUE) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
484 end_time1 = st->start_time + st->duration;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
485 if (end_time1 > end_time)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
486 end_time = end_time1;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
487 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
488 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
489 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
490 if (start_time != MAXINT64) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
491 ic->start_time = start_time;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
492 if (end_time != MAXINT64) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
493 ic->duration = end_time - start_time;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
494 if (ic->file_size > 0) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
495 /* compute the bit rate */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
496 ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE /
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
497 (double)ic->duration;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
498 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
499 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
500 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
501
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
502 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
503
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
504 static void fill_all_stream_timings(AVFormatContext *ic)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
505 {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
506 int i;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
507 AVStream *st;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
508
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
509 av_update_stream_timings(ic);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
510 for(i = 0;i < ic->nb_streams; i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
511 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
512 if (st->start_time == AV_NOPTS_VALUE) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
513 st->start_time = ic->start_time;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
514 st->duration = ic->duration;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
515 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
516 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
517 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
518
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
519 static void av_estimate_timings_from_bit_rate(AVFormatContext *ic)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
520 {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
521 int64_t filesize, duration;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
522 int bit_rate, i;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
523 AVStream *st;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
524
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
525 /* if bit_rate is already set, we believe it */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
526 if (ic->bit_rate == 0) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
527 bit_rate = 0;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
528 for(i=0;i<ic->nb_streams;i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
529 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
530 bit_rate += st->codec.bit_rate;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
531 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
532 ic->bit_rate = bit_rate;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
533 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
534
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
535 /* if duration is already set, we believe it */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
536 if (ic->duration == AV_NOPTS_VALUE &&
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
537 ic->bit_rate != 0 &&
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
538 ic->file_size != 0) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
539 filesize = ic->file_size;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
540 if (filesize > 0) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
541 duration = (int64_t)((8 * AV_TIME_BASE * (double)filesize) / (double)ic->bit_rate);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
542 for(i = 0; i < ic->nb_streams; i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
543 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
544 if (st->start_time == AV_NOPTS_VALUE ||
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
545 st->duration == AV_NOPTS_VALUE) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
546 st->start_time = 0;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
547 st->duration = duration;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
548 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
549 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
550 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
551 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
552 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
553
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
554 static void flush_packet_queue(AVFormatContext *s)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
555 {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
556 AVPacketList *pktl;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
557
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
558 for(;;) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
559 pktl = s->packet_buffer;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
560 if (!pktl)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
561 break;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
562 s->packet_buffer = pktl->next;
224
8d1569be0ee1 memory leak fix by (Tom Dexter <devel at www dot digitalaudiorock dot com>)
michaelni
parents: 205
diff changeset
563 av_free_packet(&pktl->pkt);
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
564 av_free(pktl);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
565 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
566 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
567
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
568 #define DURATION_MAX_READ_SIZE 250000
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
569
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
570 /* only usable for MPEG-PS streams */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
571 static void av_estimate_timings_from_pts(AVFormatContext *ic)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
572 {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
573 AVPacket pkt1, *pkt = &pkt1;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
574 AVStream *st;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
575 int read_size, i, ret;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
576 int64_t start_time, end_time, end_time1;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
577 int64_t filesize, offset, duration;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
578
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
579 /* we read the first packets to get the first PTS (not fully
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
580 accurate, but it is enough now) */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
581 url_fseek(&ic->pb, 0, SEEK_SET);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
582 read_size = 0;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
583 for(;;) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
584 if (read_size >= DURATION_MAX_READ_SIZE)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
585 break;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
586 /* if all info is available, we can stop */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
587 for(i = 0;i < ic->nb_streams; i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
588 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
589 if (st->start_time == AV_NOPTS_VALUE)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
590 break;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
591 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
592 if (i == ic->nb_streams)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
593 break;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
594
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
595 ret = av_read_packet(ic, pkt);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
596 if (ret != 0)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
597 break;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
598 read_size += pkt->size;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
599 st = ic->streams[pkt->stream_index];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
600 if (pkt->pts != AV_NOPTS_VALUE) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
601 if (st->start_time == AV_NOPTS_VALUE)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
602 st->start_time = (int64_t)((double)pkt->pts * ic->pts_num * (double)AV_TIME_BASE / ic->pts_den);
224
8d1569be0ee1 memory leak fix by (Tom Dexter <devel at www dot digitalaudiorock dot com>)
michaelni
parents: 205
diff changeset
603 }
8d1569be0ee1 memory leak fix by (Tom Dexter <devel at www dot digitalaudiorock dot com>)
michaelni
parents: 205
diff changeset
604 av_free_packet(pkt);
8d1569be0ee1 memory leak fix by (Tom Dexter <devel at www dot digitalaudiorock dot com>)
michaelni
parents: 205
diff changeset
605 }
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
606
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
607 /* we compute the minimum start_time and use it as default */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
608 start_time = MAXINT64;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
609 for(i = 0; i < ic->nb_streams; i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
610 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
611 if (st->start_time != AV_NOPTS_VALUE &&
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
612 st->start_time < start_time)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
613 start_time = st->start_time;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
614 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
615 if (start_time != MAXINT64)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
616 ic->start_time = start_time;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
617
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
618 /* estimate the end time (duration) */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
619 /* XXX: may need to support wrapping */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
620 filesize = ic->file_size;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
621 offset = filesize - DURATION_MAX_READ_SIZE;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
622 if (offset < 0)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
623 offset = 0;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
624
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
625 /* flush packet queue */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
626 flush_packet_queue(ic);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
627
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
628 url_fseek(&ic->pb, offset, SEEK_SET);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
629 read_size = 0;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
630 for(;;) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
631 if (read_size >= DURATION_MAX_READ_SIZE)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
632 break;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
633 /* if all info is available, we can stop */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
634 for(i = 0;i < ic->nb_streams; i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
635 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
636 if (st->duration == AV_NOPTS_VALUE)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
637 break;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
638 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
639 if (i == ic->nb_streams)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
640 break;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
641
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
642 ret = av_read_packet(ic, pkt);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
643 if (ret != 0)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
644 break;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
645 read_size += pkt->size;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
646 st = ic->streams[pkt->stream_index];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
647 if (pkt->pts != AV_NOPTS_VALUE) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
648 end_time = (int64_t)((double)pkt->pts * ic->pts_num * (double)AV_TIME_BASE / ic->pts_den);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
649 duration = end_time - st->start_time;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
650 if (duration > 0) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
651 if (st->duration == AV_NOPTS_VALUE ||
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
652 st->duration < duration)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
653 st->duration = duration;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
654 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
655 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
656 av_free_packet(pkt);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
657 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
658
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
659 /* estimate total duration */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
660 end_time = MININT64;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
661 for(i = 0;i < ic->nb_streams; i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
662 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
663 if (st->duration != AV_NOPTS_VALUE) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
664 end_time1 = st->start_time + st->duration;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
665 if (end_time1 > end_time)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
666 end_time = end_time1;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
667 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
668 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
669
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
670 /* update start_time (new stream may have been created, so we do
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
671 it at the end */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
672 if (ic->start_time != AV_NOPTS_VALUE) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
673 for(i = 0; i < ic->nb_streams; i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
674 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
675 if (st->start_time == AV_NOPTS_VALUE)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
676 st->start_time = ic->start_time;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
677 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
678 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
679
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
680 if (end_time != MININT64) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
681 /* put dummy values for duration if needed */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
682 for(i = 0;i < ic->nb_streams; i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
683 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
684 if (st->duration == AV_NOPTS_VALUE &&
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
685 st->start_time != AV_NOPTS_VALUE)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
686 st->duration = end_time - st->start_time;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
687 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
688 ic->duration = end_time - ic->start_time;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
689 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
690
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
691 url_fseek(&ic->pb, 0, SEEK_SET);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
692 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
693
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
694 static void av_estimate_timings(AVFormatContext *ic)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
695 {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
696 URLContext *h;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
697 int64_t file_size;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
698
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
699 /* get the file size, if possible */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
700 if (ic->iformat->flags & AVFMT_NOFILE) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
701 file_size = 0;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
702 } else {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
703 h = url_fileno(&ic->pb);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
704 file_size = url_filesize(h);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
705 if (file_size < 0)
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
706 file_size = 0;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
707 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
708 ic->file_size = file_size;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
709
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
710 if (ic->iformat == &mpegps_demux) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
711 /* get accurate estimate from the PTSes */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
712 av_estimate_timings_from_pts(ic);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
713 } else if (av_has_timings(ic)) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
714 /* at least one components has timings - we use them for all
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
715 the components */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
716 fill_all_stream_timings(ic);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
717 } else {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
718 /* less precise: use bit rate info */
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
719 av_estimate_timings_from_bit_rate(ic);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
720 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
721 av_update_stream_timings(ic);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
722
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
723 #if 0
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
724 {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
725 int i;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
726 AVStream *st;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
727 for(i = 0;i < ic->nb_streams; i++) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
728 st = ic->streams[i];
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
729 printf("%d: start_time: %0.3f duration: %0.3f\n",
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
730 i, (double)st->start_time / AV_TIME_BASE,
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
731 (double)st->duration / AV_TIME_BASE);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
732 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
733 printf("stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\n",
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
734 (double)ic->start_time / AV_TIME_BASE,
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
735 (double)ic->duration / AV_TIME_BASE,
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
736 ic->bit_rate / 1000);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
737 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
738 #endif
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
739 }
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
740
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
741 /* state for codec information */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
742 #define CSTATE_NOTFOUND 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
743 #define CSTATE_DECODING 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
744 #define CSTATE_FOUND 2
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
746 static int has_codec_parameters(AVCodecContext *enc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
747 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
748 int val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
749 switch(enc->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
750 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
751 val = enc->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
752 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
753 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
754 val = enc->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
755 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
756 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
757 val = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
758 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
759 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 return (val != 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
761 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
763 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764 * Read the beginning of a media file to get stream information. This
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765 * is useful for file formats with no headers such as MPEG. This
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
766 * function also compute the real frame rate in case of mpeg2 repeat
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 * frame mode.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
768 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 * @param ic media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
770 * @return >=0 if OK. AVERROR_xxx if error.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
771 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772 int av_find_stream_info(AVFormatContext *ic)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
773 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774 int i, count, ret, got_picture, size, read_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
775 AVCodec *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
776 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
777 AVPacket *pkt;
7
47e502ac6349 AVVideoFrame -> AVFrame
michaelni
parents: 5
diff changeset
778 AVFrame picture;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
779 AVPacketList *pktl=NULL, **ppktl;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
780 short samples[AVCODEC_MAX_AUDIO_FRAME_SIZE / 2];
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
781 uint8_t *ptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
782 int min_read_size, max_read_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
783
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
784 /* typical mpeg ts rate is 40 Mbits. DVD rate is about 10
127
b7ce3b3dc171 VOB stream patch ba (Brian Foley <bfoley at compsoc dot nuigalway dot ie>)
michaelni
parents: 90
diff changeset
785 Mbits. We read at most 0.2 second of file to find all streams */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
786
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
787 /* XXX: base it on stream bitrate when possible */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
788 if (ic->iformat == &mpegts_demux) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
789 /* maximum number of bytes we accept to read to find all the streams
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
790 in a file */
127
b7ce3b3dc171 VOB stream patch ba (Brian Foley <bfoley at compsoc dot nuigalway dot ie>)
michaelni
parents: 90
diff changeset
791 min_read_size = 6000000;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
792 } else {
127
b7ce3b3dc171 VOB stream patch ba (Brian Foley <bfoley at compsoc dot nuigalway dot ie>)
michaelni
parents: 90
diff changeset
793 min_read_size = 250000;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
794 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
795 /* max read size is 2 seconds of video max */
127
b7ce3b3dc171 VOB stream patch ba (Brian Foley <bfoley at compsoc dot nuigalway dot ie>)
michaelni
parents: 90
diff changeset
796 max_read_size = min_read_size * 10;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
797
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
798 /* set initial codec state */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
800 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
801 if (has_codec_parameters(&st->codec))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
802 st->codec_info_state = CSTATE_FOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
803 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
804 st->codec_info_state = CSTATE_NOTFOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
805 st->codec_info_nb_repeat_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
806 st->codec_info_nb_real_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
807 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
808
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
809 count = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
810 read_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
811 ppktl = &ic->packet_buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
812 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
813 /* check if one codec still needs to be handled */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
814 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
815 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
816 if (st->codec_info_state != CSTATE_FOUND)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
817 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
818 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
819 if (i == ic->nb_streams) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
820 /* NOTE: if the format has no header, then we need to read
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
821 some packets to get most of the streams, so we cannot
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
822 stop here */
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
823 if (!(ic->ctx_flags & AVFMTCTX_NOHEADER) ||
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
824 read_size >= min_read_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
825 /* if we found the info for all the codecs, we can stop */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
826 ret = count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
827 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
828 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
829 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
830 /* we did not get all the codec info, but we read too much data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
831 if (read_size >= max_read_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
832 ret = count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
833 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
834 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
835 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
836
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
837 pktl = av_mallocz(sizeof(AVPacketList));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
838 if (!pktl) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839 ret = AVERROR_NOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
840 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
842
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
843 /* add the packet in the buffered packet list */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
844 *ppktl = pktl;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
845 ppktl = &pktl->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
846
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
847 /* NOTE: a new stream can be added there if no header in file
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
848 (AVFMTCTX_NOHEADER) */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
849 pkt = &pktl->pkt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
850 if (ic->iformat->read_packet(ic, pkt) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
851 /* EOF or error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
852 ret = -1; /* we could not have all the codec parameters before EOF */
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
853 if ((ic->ctx_flags & AVFMTCTX_NOHEADER) &&
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
854 i == ic->nb_streams)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
855 ret = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
856 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
857 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
858 read_size += pkt->size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
859
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
860 /* open new codecs */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
861 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
862 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
863 if (st->codec_info_state == CSTATE_NOTFOUND) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
864 /* set to found in case of error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
865 st->codec_info_state = CSTATE_FOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
866 codec = avcodec_find_decoder(st->codec.codec_id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
867 if (codec) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
868 if(codec->capabilities & CODEC_CAP_TRUNCATED)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
869 st->codec.flags |= CODEC_FLAG_TRUNCATED;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
870
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
871 ret = avcodec_open(&st->codec, codec);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
872 if (ret >= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
873 st->codec_info_state = CSTATE_DECODING;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
874 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
875 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
876 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
877
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
878 st = ic->streams[pkt->stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
879 if (st->codec_info_state == CSTATE_DECODING) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
880 /* decode the data and update codec parameters */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
881 ptr = pkt->data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
882 size = pkt->size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
883 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
884 switch(st->codec.codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
885 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
886 ret = avcodec_decode_video(&st->codec, &picture,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
887 &got_picture, ptr, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
888 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
889 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
890 ret = avcodec_decode_audio(&st->codec, samples,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
891 &got_picture, ptr, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
892 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
893 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
894 ret = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
895 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
896 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
897 if (ret < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
898 /* if error, simply ignore because another packet
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
899 may be OK */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
900 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
901 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
902 if (got_picture) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
903 /* we got the parameters - now we can stop
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
904 examining this stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
905 /* XXX: add a codec info so that we can decide if
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
906 the codec can repeat frames */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
907 if (st->codec.codec_id == CODEC_ID_MPEG1VIDEO &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
908 ic->iformat != &mpegts_demux &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
909 st->codec.sub_id == 2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
910 /* for mpeg2 video, we want to know the real
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
911 frame rate, so we decode 40 frames. In mpeg
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
912 TS case we do not do it because it would be
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
913 too long */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
914 st->codec_info_nb_real_frames++;
70
e851fa232508 move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents: 65
diff changeset
915 st->codec_info_nb_repeat_frames += st->codec.coded_frame->repeat_pict;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
916 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
917 /* XXX: testing */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
918 if ((st->codec_info_nb_real_frames % 24) == 23) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
919 st->codec_info_nb_repeat_frames += 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
920 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
921 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
922 /* stop after 40 frames */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
923 if (st->codec_info_nb_real_frames >= 40) {
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
924 av_reduce(
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
925 &st->r_frame_rate,
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
926 &st->r_frame_rate_base,
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
927 (int64_t)st->codec.frame_rate * st->codec_info_nb_real_frames,
162
35386fc4d47d mpeg1 bad frame_rate_base fix by (Arthur van Hoff (javanator))
michaelni
parents: 127
diff changeset
928 (st->codec_info_nb_real_frames + (st->codec_info_nb_repeat_frames >> 1)) * st->codec.frame_rate_base,
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
929 1<<30);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
930 goto close_codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
931 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
932 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
933 close_codec:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
934 st->codec_info_state = CSTATE_FOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
935 avcodec_close(&st->codec);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
936 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
937 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
938 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
939 ptr += ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
940 size -= ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
941 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
942 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
943 count++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
944 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
945
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
946 /* close each codec if there are opened */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
947 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
948 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
949 if (st->codec_info_state == CSTATE_DECODING)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
950 avcodec_close(&st->codec);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
951 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
952
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
953 /* set real frame rate info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
954 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
955 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
956 if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
957 if (!st->r_frame_rate){
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
958 st->r_frame_rate = st->codec.frame_rate;
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
959 st->r_frame_rate_base = st->codec.frame_rate_base;
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
960 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
961 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
962 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
963
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
964
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
965 av_estimate_timings(ic);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
966 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
967 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
968
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
969 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
970 * Close a media file (but not its codecs)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
971 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
972 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
973 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
974 void av_close_input_file(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
975 {
172
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
976 int i, must_open_file;
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
977 AVStream *st;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
978
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
979 if (s->iformat->read_close)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
980 s->iformat->read_close(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
981 for(i=0;i<s->nb_streams;i++) {
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
982 /* free all data in a stream component */
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
983 st = s->streams[i];
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
984 av_free(st);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
985 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
986 if (s->packet_buffer) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
987 AVPacketList *p, *p1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
988 p = s->packet_buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
989 while (p != NULL) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
990 p1 = p->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
991 av_free_packet(&p->pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
992 av_free(p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
993 p = p1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
994 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
995 s->packet_buffer = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
996 }
172
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
997 must_open_file = 1;
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
998 if (s->iformat->flags & AVFMT_NOFILE) {
172
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
999 must_open_file = 0;
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
1000 }
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
1001 if (must_open_file) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1002 url_fclose(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1003 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1004 av_freep(&s->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1005 av_free(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1006 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1007
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1008 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1009 * Add a new stream to a media file. Can only be called in the
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
1010 * read_header function. If the flag AVFMTCTX_NOHEADER is in the
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
1011 * format context, then new streams can be added in read_packet too.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1012 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1013 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1014 * @param s media file handle
293
62cec412a186 make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents: 290
diff changeset
1015 * @param id file format dependent stream id
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1016 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1017 AVStream *av_new_stream(AVFormatContext *s, int id)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1018 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1019 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1020
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1021 if (s->nb_streams >= MAX_STREAMS)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1022 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1023
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1024 st = av_mallocz(sizeof(AVStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1025 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1026 return NULL;
5
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
1027 avcodec_get_context_defaults(&st->codec);
193
5079b6e20e91 no default bit rate if decoding
bellard
parents: 192
diff changeset
1028 if (s->iformat) {
5079b6e20e91 no default bit rate if decoding
bellard
parents: 192
diff changeset
1029 /* no default bitrate if decoding */
5079b6e20e91 no default bit rate if decoding
bellard
parents: 192
diff changeset
1030 st->codec.bit_rate = 0;
5079b6e20e91 no default bit rate if decoding
bellard
parents: 192
diff changeset
1031 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1032 st->index = s->nb_streams;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1033 st->id = id;
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1034 st->start_time = AV_NOPTS_VALUE;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1035 st->duration = AV_NOPTS_VALUE;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1036 s->streams[s->nb_streams++] = st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1037 return st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1038 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1039
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1040 /************************************************************/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1041 /* output media file */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1042
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1043 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1044 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1045 int ret;
32
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
1046
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
1047 if (s->oformat->priv_data_size > 0) {
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
1048 s->priv_data = av_mallocz(s->oformat->priv_data_size);
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
1049 if (!s->priv_data)
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
1050 return AVERROR_NOMEM;
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
1051 } else
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
1052 s->priv_data = NULL;
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
1053
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1054 if (s->oformat->set_parameters) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1055 ret = s->oformat->set_parameters(s, ap);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1056 if (ret < 0)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1057 return ret;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1058 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1059 return 0;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1060 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1061
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1062 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1063 * allocate the stream private data and write the stream header to an
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1064 * output media file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1065 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1066 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1067 * @return 0 if OK. AVERROR_xxx if error.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1068 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1069 int av_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1070 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1071 int ret, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1072 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1073
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1074 /* default pts settings is MPEG like */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1075 av_set_pts_info(s, 33, 1, 90000);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1076 ret = s->oformat->write_header(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1077 if (ret < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1078 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1079
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1080 /* init PTS generation */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1081 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1082 st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1083
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1084 switch (st->codec.codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1085 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1086 av_frac_init(&st->pts, 0, 0,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1087 (int64_t)s->pts_num * st->codec.sample_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1088 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1089 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1090 av_frac_init(&st->pts, 0, 0,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1091 (int64_t)s->pts_num * st->codec.frame_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1092 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1093 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1094 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1095 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1096 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1097 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1098 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1099
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1100 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1101 * Write a packet to an output media file. The packet shall contain
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1102 * one audio or video frame.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1103 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1104 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1105 * @param stream_index stream index
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1106 * @param buf buffer containing the frame data
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1107 * @param size size of buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1108 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1109 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1110 int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1111 int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1112 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1113 AVStream *st;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1114 int64_t pts_mask;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1115 int ret, frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1116
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1117 st = s->streams[stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1118 pts_mask = (1LL << s->pts_wrap_bits) - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1119 ret = s->oformat->write_packet(s, stream_index, (uint8_t *)buf, size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1120 st->pts.val & pts_mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1121 if (ret < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1122 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1123
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1124 /* update pts */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1125 switch (st->codec.codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1126 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1127 if (st->codec.frame_size <= 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1128 frame_size = size / st->codec.channels;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1129 /* specific hack for pcm codecs because no frame size is provided */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1130 switch(st->codec.codec_id) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1131 case CODEC_ID_PCM_S16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1132 case CODEC_ID_PCM_S16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1133 case CODEC_ID_PCM_U16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1134 case CODEC_ID_PCM_U16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1135 frame_size >>= 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1136 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1137 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1138 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1139 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1140 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1141 frame_size = st->codec.frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1142 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1143 av_frac_add(&st->pts,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1144 (int64_t)s->pts_den * frame_size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1145 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1146 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1147 av_frac_add(&st->pts,
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
1148 (int64_t)s->pts_den * st->codec.frame_rate_base);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1149 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1150 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1151 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1152 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1153 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1154 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1155
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1156 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1157 * write the stream trailer to an output media file and and free the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1158 * file private data.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1159 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1160 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1161 * @return 0 if OK. AVERROR_xxx if error. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1162 int av_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1163 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1164 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1165 ret = s->oformat->write_trailer(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1166 av_freep(&s->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1167 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1168 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1169
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1170 /* "user interface" functions */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1171
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1172 void dump_format(AVFormatContext *ic,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1173 int index,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1174 const char *url,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1175 int is_output)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1176 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1177 int i, flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1178 char buf[256];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1179
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1180 fprintf(stderr, "%s #%d, %s, %s '%s':\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1181 is_output ? "Output" : "Input",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1182 index,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1183 is_output ? ic->oformat->name : ic->iformat->name,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1184 is_output ? "to" : "from", url);
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1185 if (!is_output) {
197
b8a3fb61d39a all human-readable output should go into stderr for now. We really
romansh
parents: 193
diff changeset
1186 fprintf(stderr, " Duration: ");
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1187 if (ic->duration != AV_NOPTS_VALUE) {
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1188 int hours, mins, secs, us;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1189 secs = ic->duration / AV_TIME_BASE;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1190 us = ic->duration % AV_TIME_BASE;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1191 mins = secs / 60;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1192 secs %= 60;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1193 hours = mins / 60;
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1194 mins %= 60;
197
b8a3fb61d39a all human-readable output should go into stderr for now. We really
romansh
parents: 193
diff changeset
1195 fprintf(stderr, "%02d:%02d:%02d.%01d", hours, mins, secs,
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1196 (10 * us) / AV_TIME_BASE);
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1197 } else {
197
b8a3fb61d39a all human-readable output should go into stderr for now. We really
romansh
parents: 193
diff changeset
1198 fprintf(stderr, "N/A");
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1199 }
197
b8a3fb61d39a all human-readable output should go into stderr for now. We really
romansh
parents: 193
diff changeset
1200 fprintf(stderr, ", bitrate: ");
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1201 if (ic->bit_rate) {
197
b8a3fb61d39a all human-readable output should go into stderr for now. We really
romansh
parents: 193
diff changeset
1202 fprintf(stderr,"%d kb/s", ic->bit_rate / 1000);
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1203 } else {
197
b8a3fb61d39a all human-readable output should go into stderr for now. We really
romansh
parents: 193
diff changeset
1204 fprintf(stderr, "N/A");
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1205 }
197
b8a3fb61d39a all human-readable output should go into stderr for now. We really
romansh
parents: 193
diff changeset
1206 fprintf(stderr, "\n");
192
0316a506aeb0 initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents: 175
diff changeset
1207 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1208 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1209 AVStream *st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1210 avcodec_string(buf, sizeof(buf), &st->codec, is_output);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1211 fprintf(stderr, " Stream #%d.%d", index, i);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1212 /* the pid is an important information, so we display it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1213 /* XXX: add a generic system */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1214 if (is_output)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1215 flags = ic->oformat->flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1216 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1217 flags = ic->iformat->flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1218 if (flags & AVFMT_SHOW_IDS) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1219 fprintf(stderr, "[0x%x]", st->id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1220 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1221 fprintf(stderr, ": %s\n", buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1222 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1223 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1224
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1225 typedef struct {
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1226 const char *abv;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1227 int width, height;
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1228 int frame_rate, frame_rate_base;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1229 } AbvEntry;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1230
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1231 static AbvEntry frame_abvs[] = {
204
61f9cad50ff3 * making resolution abbreviations right
romansh
parents: 199
diff changeset
1232 { "ntsc", 720, 480, 30000, 1001 },
61f9cad50ff3 * making resolution abbreviations right
romansh
parents: 199
diff changeset
1233 { "pal", 720, 576, 25, 1 },
61f9cad50ff3 * making resolution abbreviations right
romansh
parents: 199
diff changeset
1234 { "qntsc", 352, 240, 30000, 1001 }, /* VCD compliant ntsc */
61f9cad50ff3 * making resolution abbreviations right
romansh
parents: 199
diff changeset
1235 { "qpal", 352, 288, 25, 1 }, /* VCD compliant pal */
205
e5491d64edb3 1000l in abbrv. table
romansh
parents: 204
diff changeset
1236 { "sntsc", 640, 480, 30000, 1001 }, /* square pixel ntsc */
e5491d64edb3 1000l in abbrv. table
romansh
parents: 204
diff changeset
1237 { "spal", 768, 576, 25, 1 }, /* square pixel pal */
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1238 { "film", 352, 240, 24, 1 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1239 { "ntsc-film", 352, 240, 24000, 1001 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1240 { "sqcif", 128, 96, 0, 0 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1241 { "qcif", 176, 144, 0, 0 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1242 { "cif", 352, 288, 0, 0 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1243 { "4cif", 704, 576, 0, 0 },
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1244 };
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1245
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1246 int parse_image_size(int *width_ptr, int *height_ptr, const char *str)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1247 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1248 int i;
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1249 int n = sizeof(frame_abvs) / sizeof(AbvEntry);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1250 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1251 int frame_width = 0, frame_height = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1252
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1253 for(i=0;i<n;i++) {
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1254 if (!strcmp(frame_abvs[i].abv, str)) {
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1255 frame_width = frame_abvs[i].width;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1256 frame_height = frame_abvs[i].height;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1257 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1258 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1259 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1260 if (i == n) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1261 p = str;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1262 frame_width = strtol(p, (char **)&p, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1263 if (*p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1264 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1265 frame_height = strtol(p, (char **)&p, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1266 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1267 if (frame_width <= 0 || frame_height <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1268 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1269 *width_ptr = frame_width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1270 *height_ptr = frame_height;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1271 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1272 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1273
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1274 int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg)
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1275 {
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1276 int i;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1277 char* cp;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1278
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1279 /* First, we check our abbreviation table */
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1280 for (i = 0; i < sizeof(frame_abvs)/sizeof(*frame_abvs); ++i)
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1281 if (!strcmp(frame_abvs[i].abv, arg)) {
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1282 *frame_rate = frame_abvs[i].frame_rate;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1283 *frame_rate_base = frame_abvs[i].frame_rate_base;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1284 return 0;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1285 }
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1286
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1287 /* Then, we try to parse it as fraction */
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1288 cp = strchr(arg, '/');
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1289 if (cp) {
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1290 char* cpp;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1291 *frame_rate = strtol(arg, &cpp, 10);
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1292 if (cpp != arg || cpp == cp)
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1293 *frame_rate_base = strtol(cp+1, &cpp, 10);
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1294 else
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1295 *frame_rate = 0;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1296 }
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1297 else {
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1298 /* Finally we give up and parse it as double */
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1299 *frame_rate_base = DEFAULT_FRAME_RATE_BASE;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1300 *frame_rate = (int)(strtod(arg, 0) * (*frame_rate_base) + 0.5);
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1301 }
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1302 if (!*frame_rate || !*frame_rate_base)
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1303 return -1;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1304 else
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1305 return 0;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1306 }
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
1307
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1308 /* Syntax:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1309 * - If not a duration:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1310 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1311 * Time is localtime unless Z is suffixed to the end. In this case GMT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1312 * Return the date in micro seconds since 1970
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1313 * - If duration:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1314 * HH[:MM[:SS[.m...]]]
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1315 * S+[.m...]
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1316 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1317 int64_t parse_date(const char *datestr, int duration)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1318 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1319 const char *p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1320 int64_t t;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1321 struct tm dt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1322 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1323 static const char *date_fmt[] = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1324 "%Y-%m-%d",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1325 "%Y%m%d",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1326 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1327 static const char *time_fmt[] = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1328 "%H:%M:%S",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1329 "%H%M%S",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1330 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1331 const char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1332 int is_utc, len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1333 char lastch;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1334 time_t now = time(0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1335
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1336 len = strlen(datestr);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1337 if (len > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1338 lastch = datestr[len - 1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1339 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1340 lastch = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1341 is_utc = (lastch == 'z' || lastch == 'Z');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1342
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1343 memset(&dt, 0, sizeof(dt));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1344
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1345 p = datestr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1346 q = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1347 if (!duration) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1348 for (i = 0; i < sizeof(date_fmt) / sizeof(date_fmt[0]); i++) {
230
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
1349 q = small_strptime(p, date_fmt[i], &dt);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1350 if (q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1351 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1352 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1353 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1354
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1355 if (!q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1356 if (is_utc) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1357 dt = *gmtime(&now);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1358 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1359 dt = *localtime(&now);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1360 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1361 dt.tm_hour = dt.tm_min = dt.tm_sec = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1362 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1363 p = q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1364 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1365
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1366 if (*p == 'T' || *p == 't' || *p == ' ')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1367 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1368
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1369 for (i = 0; i < sizeof(time_fmt) / sizeof(time_fmt[0]); i++) {
230
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
1370 q = small_strptime(p, time_fmt[i], &dt);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1371 if (q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1372 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1373 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1374 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1375 } else {
230
9f4f4ca9f7b5 simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents: 229
diff changeset
1376 q = small_strptime(p, time_fmt[0], &dt);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1377 if (!q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1378 dt.tm_sec = strtol(p, (char **)&q, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1379 dt.tm_min = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1380 dt.tm_hour = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1381 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1382 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1383
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1384 /* Now we have all the fields that we can get */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1385 if (!q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1386 if (duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1387 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1388 else
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1389 return now * int64_t_C(1000000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1390 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1391
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1392 if (duration) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1393 t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1394 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1395 dt.tm_isdst = -1; /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1396 if (is_utc) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1397 t = mktimegm(&dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1398 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1399 t = mktime(&dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1400 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1401 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1402
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1403 t *= 1000000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1404
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1405 if (*q == '.') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1406 int val, n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1407 q++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1408 for (val = 0, n = 100000; n >= 1; n /= 10, q++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1409 if (!isdigit(*q))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1410 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1411 val += n * (*q - '0');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1412 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1413 t += val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1414 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1415 return t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1416 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1417
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1418 /* syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. Return
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1419 1 if found */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1420 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1421 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1422 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1423 char tag[128], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1424
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1425 p = info;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1426 if (*p == '?')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1427 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1428 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1429 q = tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1430 while (*p != '\0' && *p != '=' && *p != '&') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1431 if ((q - tag) < sizeof(tag) - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1432 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1433 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1434 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1435 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1436 q = arg;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1437 if (*p == '=') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1438 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1439 while (*p != '&' && *p != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1440 if ((q - arg) < arg_size - 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1441 if (*p == '+')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1442 *q++ = ' ';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1443 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1444 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1445 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1446 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1447 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1448 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1449 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1450 if (!strcmp(tag, tag1))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1451 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1452 if (*p != '&')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1453 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1454 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1455 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1456 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1457 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1458
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1459 /* Return in 'buf' the path with '%d' replaced by number. Also handles
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1460 the '%0nd' format where 'n' is the total number of digits and
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1461 '%%'. Return 0 if OK, and -1 if format error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1462 int get_frame_filename(char *buf, int buf_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1463 const char *path, int number)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1464 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1465 const char *p;
290
7a3ed84008ec GCC 3.3.2 warnings patch by (Panagiotis Issaris <takis at lumumba dot luc dot ac dot be>)
michael
parents: 230
diff changeset
1466 char *q, buf1[20], c;
7a3ed84008ec GCC 3.3.2 warnings patch by (Panagiotis Issaris <takis at lumumba dot luc dot ac dot be>)
michael
parents: 230
diff changeset
1467 int nd, len, percentd_found;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1468
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1469 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1470 p = path;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1471 percentd_found = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1472 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1473 c = *p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1474 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1475 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1476 if (c == '%') {
9
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1477 do {
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1478 nd = 0;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1479 while (isdigit(*p)) {
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1480 nd = nd * 10 + *p++ - '0';
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1481 }
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1482 c = *p++;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1483 } while (isdigit(c));
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1484
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1485 switch(c) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1486 case '%':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1487 goto addchar;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1488 case 'd':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1489 if (percentd_found)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1490 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1491 percentd_found = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1492 snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1493 len = strlen(buf1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1494 if ((q - buf + len) > buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1495 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1496 memcpy(q, buf1, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1497 q += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1498 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1499 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1500 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1501 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1502 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1503 addchar:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1504 if ((q - buf) < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1505 *q++ = c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1506 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1507 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1508 if (!percentd_found)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1509 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1510 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1511 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1512 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1513 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1514 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1515 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1516
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1517 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1518 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1519 * Print on stdout a nice hexa dump of a buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1520 * @param buf buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1521 * @param size buffer size
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1522 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1523 void av_hex_dump(uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1524 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1525 int len, i, j, c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1526
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1527 for(i=0;i<size;i+=16) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1528 len = size - i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1529 if (len > 16)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1530 len = 16;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1531 printf("%08x ", i);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1532 for(j=0;j<16;j++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1533 if (j < len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1534 printf(" %02x", buf[i+j]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1535 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1536 printf(" ");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1537 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1538 printf(" ");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1539 for(j=0;j<len;j++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1540 c = buf[i+j];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1541 if (c < ' ' || c > '~')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1542 c = '.';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1543 printf("%c", c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1544 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1545 printf("\n");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1546 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1547 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1548
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1549 void url_split(char *proto, int proto_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1550 char *hostname, int hostname_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1551 int *port_ptr,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1552 char *path, int path_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1553 const char *url)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1554 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1555 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1556 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1557 int port;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1558
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1559 port = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1560
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1561 p = url;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1562 q = proto;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1563 while (*p != ':' && *p != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1564 if ((q - proto) < proto_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1565 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1566 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1567 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1568 if (proto_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1569 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1570 if (*p == '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1571 if (proto_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1572 proto[0] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1573 if (hostname_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1574 hostname[0] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1575 p = url;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1576 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1577 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1578 if (*p == '/')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1579 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1580 if (*p == '/')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1581 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1582 q = hostname;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1583 while (*p != ':' && *p != '/' && *p != '?' && *p != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1584 if ((q - hostname) < hostname_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1585 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1586 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1587 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1588 if (hostname_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1589 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1590 if (*p == ':') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1591 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1592 port = strtoul(p, (char **)&p, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1593 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1594 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1595 if (port_ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1596 *port_ptr = port;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1597 pstrcpy(path, path_size, p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1598 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1599
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1600 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1601 * Set the pts for a given stream
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1602 * @param s stream
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1603 * @param pts_wrap_bits number of bits effectively used by the pts
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1604 * (used for wrap control, 33 is the value for MPEG)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1605 * @param pts_num numerator to convert to seconds (MPEG: 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1606 * @param pts_den denominator to convert to seconds (MPEG: 90000)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1607 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1608 void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1609 int pts_num, int pts_den)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1610 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1611 s->pts_wrap_bits = pts_wrap_bits;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1612 s->pts_num = pts_num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1613 s->pts_den = pts_den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1614 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1615
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1616 /* fraction handling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1617
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1618 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1619 * f = val + (num / den) + 0.5. 'num' is normalized so that it is such
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1620 * as 0 <= num < den.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1621 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1622 * @param f fractional number
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1623 * @param val integer value
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1624 * @param num must be >= 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1625 * @param den must be >= 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1626 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1627 void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1628 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1629 num += (den >> 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1630 if (num >= den) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1631 val += num / den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1632 num = num % den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1633 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1634 f->val = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1635 f->num = num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1636 f->den = den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1637 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1638
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1639 /* set f to (val + 0.5) */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1640 void av_frac_set(AVFrac *f, int64_t val)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1641 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1642 f->val = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1643 f->num = f->den >> 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1644 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1645
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1646 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1647 * Fractionnal addition to f: f = f + (incr / f->den)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1648 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1649 * @param f fractional number
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1650 * @param incr increment, can be positive or negative
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1651 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1652 void av_frac_add(AVFrac *f, int64_t incr)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1653 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1654 int64_t num, den;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1655
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1656 num = f->num + incr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1657 den = f->den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1658 if (num < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1659 f->val += num / den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1660 num = num % den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1661 if (num < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1662 num += den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1663 f->val--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1664 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1665 } else if (num >= den) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1666 f->val += num / den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1667 num = num % den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1668 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1669 f->num = num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1670 }
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1671
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1672 /**
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1673 * register a new image format
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1674 * @param img_fmt Image format descriptor
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1675 */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1676 void av_register_image_format(AVImageFormat *img_fmt)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1677 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1678 AVImageFormat **p;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1679
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1680 p = &first_image_format;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1681 while (*p != NULL) p = &(*p)->next;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1682 *p = img_fmt;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1683 img_fmt->next = NULL;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1684 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1685
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1686 /* guess image format */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1687 AVImageFormat *av_probe_image_format(AVProbeData *pd)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1688 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1689 AVImageFormat *fmt1, *fmt;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1690 int score, score_max;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1691
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1692 fmt = NULL;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1693 score_max = 0;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1694 for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1695 if (fmt1->img_probe) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1696 score = fmt1->img_probe(pd);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1697 if (score > score_max) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1698 score_max = score;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1699 fmt = fmt1;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1700 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1701 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1702 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1703 return fmt;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1704 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1705
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1706 AVImageFormat *guess_image_format(const char *filename)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1707 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1708 AVImageFormat *fmt1;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1709
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1710 for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1711 if (fmt1->extensions && match_ext(filename, fmt1->extensions))
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1712 return fmt1;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1713 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1714 return NULL;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1715 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1716
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1717 /**
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1718 * Read an image from a stream.
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1719 * @param gb byte stream containing the image
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1720 * @param fmt image format, NULL if probing is required
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1721 */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1722 int av_read_image(ByteIOContext *pb, const char *filename,
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1723 AVImageFormat *fmt,
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1724 int (*alloc_cb)(void *, AVImageInfo *info), void *opaque)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1725 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1726 char buf[PROBE_BUF_SIZE];
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1727 AVProbeData probe_data, *pd = &probe_data;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1728 offset_t pos;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1729 int ret;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1730
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1731 if (!fmt) {
64
b0e0eb595e29 * static,const,compiler warning cleanup
kabi
parents: 53
diff changeset
1732 pd->filename = filename;
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1733 pd->buf = buf;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1734 pos = url_ftell(pb);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1735 pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1736 url_fseek(pb, pos, SEEK_SET);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1737 fmt = av_probe_image_format(pd);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1738 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1739 if (!fmt)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1740 return AVERROR_NOFMT;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1741 ret = fmt->img_read(pb, alloc_cb, opaque);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1742 return ret;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1743 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1744
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1745 /**
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1746 * Write an image to a stream.
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1747 * @param pb byte stream for the image output
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1748 * @param fmt image format
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1749 * @param img image data and informations
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1750 */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1751 int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1752 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1753 return fmt->img_write(pb, img);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1754 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1755