annotate utils.c @ 131:5bb5f3d201d6 libavformat

* uninitialized/unused vars cleanup
author kabi
date Mon, 12 May 2003 11:07:46 +0000
parents b7ce3b3dc171
children 35386fc4d47d
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 #include <ctype.h>
22
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
21 #ifdef CONFIG_WIN32
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
22 #define strcasecmp _stricmp
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
23 #include <sys/types.h>
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
24 #include <sys/timeb.h>
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
25 #elif defined(CONFIG_OS2)
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
26 #include <string.h>
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
27 #define strcasecmp stricmp
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
28 #include <sys/time.h>
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
29 #else
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 #include <unistd.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 #include <fcntl.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 #include <sys/time.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 #include <time.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 #ifndef HAVE_STRPTIME
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 #include "strptime.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 AVInputFormat *first_iformat;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 AVOutputFormat *first_oformat;
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
42 AVImageFormat *first_image_format;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 void av_register_input_format(AVInputFormat *format)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 AVInputFormat **p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 p = &first_iformat;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 while (*p != NULL) p = &(*p)->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 *p = format;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 format->next = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 void av_register_output_format(AVOutputFormat *format)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 AVOutputFormat **p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 p = &first_oformat;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 while (*p != NULL) p = &(*p)->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 *p = format;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 format->next = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 int match_ext(const char *filename, const char *extensions)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 const char *ext, *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 char ext1[32], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 ext = strrchr(filename, '.');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 if (ext) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 ext++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 p = extensions;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 q = ext1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 while (*p != '\0' && *p != ',')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 *q++ = *p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 if (!strcasecmp(ext1, ext))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 if (*p == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 AVOutputFormat *guess_format(const char *short_name, const char *filename,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 const char *mime_type)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 AVOutputFormat *fmt, *fmt_found;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 int score_max, score;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
92 /* specific test for image sequences */
21
3d2d2f8725f9 jpeg detection fix - fixed imagepipe output
bellard
parents: 20
diff changeset
93 if (!short_name && filename &&
3d2d2f8725f9 jpeg detection fix - fixed imagepipe output
bellard
parents: 20
diff changeset
94 filename_number_test(filename) >= 0 &&
3d2d2f8725f9 jpeg detection fix - fixed imagepipe output
bellard
parents: 20
diff changeset
95 guess_image_format(filename)) {
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
96 return guess_format("image", NULL, NULL);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
97 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
98
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 /* find the proper file type */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 fmt_found = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 score_max = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 fmt = first_oformat;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 while (fmt != NULL) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 score = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 if (fmt->name && short_name && !strcmp(fmt->name, short_name))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 score += 100;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 if (fmt->mime_type && mime_type && !strcmp(fmt->mime_type, mime_type))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 score += 10;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 if (filename && fmt->extensions &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 match_ext(filename, fmt->extensions)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 score += 5;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 if (score > score_max) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 score_max = score;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 fmt_found = fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 fmt = fmt->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 return fmt_found;
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 AVOutputFormat *guess_stream_format(const char *short_name, const char *filename,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 const char *mime_type)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 AVOutputFormat *fmt = guess_format(short_name, filename, mime_type);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 if (fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 AVOutputFormat *stream_fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 char stream_format_name[64];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 snprintf(stream_format_name, sizeof(stream_format_name), "%s_stream", fmt->name);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 stream_fmt = guess_format(stream_format_name, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 if (stream_fmt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 fmt = stream_fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 return fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 AVInputFormat *av_find_input_format(const char *short_name)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 AVInputFormat *fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 for(fmt = first_iformat; fmt != NULL; fmt = fmt->next) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 if (!strcmp(fmt->name, short_name))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 return fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 /* memory handling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 /**
53
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
154 * Default packet destructor
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
155 */
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
156 static void av_destruct_packet(AVPacket *pkt)
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
157 {
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
158 av_free(pkt->data);
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
159 pkt->data = NULL; pkt->size = 0;
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
160 }
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
161
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
162 /**
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 * Allocate the payload of a packet and intialized its fields to default values.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 * @param pkt packet
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 * @param size wanted payload size
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 * @return 0 if OK. AVERROR_xxx otherwise.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 int av_new_packet(AVPacket *pkt, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 {
53
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
171 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
172 if (!data)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 return AVERROR_NOMEM;
53
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
174 memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175
53
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
176 av_init_packet(pkt);
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
177 pkt->data = data;
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
178 pkt->size = size;
fb671d87824e zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents: 32
diff changeset
179 pkt->destruct = av_destruct_packet;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 /* fifo handling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 int fifo_init(FifoBuffer *f, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 f->buffer = av_malloc(size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 if (!f->buffer)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 f->end = f->buffer + size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 f->wptr = f->rptr = f->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 void fifo_free(FifoBuffer *f)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 av_free(f->buffer);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
200 int fifo_size(FifoBuffer *f, uint8_t *rptr)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 int size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 if (f->wptr >= rptr) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 size = f->wptr - rptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 size = (f->end - rptr) + (f->wptr - f->buffer);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 return size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 /* get data from the fifo (return -1 if not enough data) */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
213 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
214 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
215 uint8_t *rptr = *rptr_ptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 int size, len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 if (f->wptr >= rptr) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 size = f->wptr - rptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 size = (f->end - rptr) + (f->wptr - f->buffer);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 if (size < buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 while (buf_size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 len = f->end - rptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 if (len > buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 len = buf_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 memcpy(buf, rptr, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 rptr += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 if (rptr >= f->end)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 rptr = f->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 buf_size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 *rptr_ptr = rptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
241 void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 int len;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
244 uint8_t *wptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 wptr = *wptr_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 len = f->end - wptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 if (len > size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 len = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 memcpy(wptr, buf, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 wptr += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 if (wptr >= f->end)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 wptr = f->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 *wptr_ptr = wptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 int filename_number_test(const char *filename)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 char buf[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 return get_frame_filename(buf, sizeof(buf), filename, 1);
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 /* guess file format */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 AVInputFormat *fmt1, *fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 int score, score_max;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 fmt = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 score_max = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 for(fmt1 = first_iformat; fmt1 != NULL; fmt1 = fmt1->next) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 if (!is_opened && !(fmt1->flags & AVFMT_NOFILE))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 continue;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 score = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 if (fmt1->read_probe) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 score = fmt1->read_probe(pd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 } else if (fmt1->extensions) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 if (match_ext(pd->filename, fmt1->extensions)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 score = 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 if (score > score_max) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 score_max = score;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 fmt = fmt1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 return fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 /************************************************************/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 /* input media file */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 #define PROBE_BUF_SIZE 2048
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 * Open a media file as input. The codec are not opened. Only the file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 * header (if present) is read.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 * @param ic_ptr the opened media file handle is put here
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 * @param filename filename to open.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 * @param fmt if non NULL, force the file format to use
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 * @param buf_size optional buffer size (zero if default is OK)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 * @param ap additionnal parameters needed when opening the file (NULL if default)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 * @return 0 if OK. AVERROR_xxx otherwise.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 AVInputFormat *fmt,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 int buf_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 AVFormatContext *ic = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 int err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 char buf[PROBE_BUF_SIZE];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 AVProbeData probe_data, *pd = &probe_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 ic = av_mallocz(sizeof(AVFormatContext));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 if (!ic) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 err = AVERROR_NOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 pstrcpy(ic->filename, sizeof(ic->filename), filename);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 pd->filename = ic->filename;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 pd->buf = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 pd->buf_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 if (!fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 /* guess format if no file can be opened */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 fmt = av_probe_input_format(pd, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 if (!fmt || !(fmt->flags & AVFMT_NOFILE)) {
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
335 /* if no file needed do not try to open one */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 if (url_fopen(&ic->pb, filename, URL_RDONLY) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 err = AVERROR_IO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 if (buf_size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 url_setbufsize(&ic->pb, buf_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 if (!fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 /* read probe data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 pd->buf_size = get_buffer(&ic->pb, buf, PROBE_BUF_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 url_fseek(&ic->pb, 0, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 /* guess file format */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 if (!fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 fmt = av_probe_input_format(pd, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 /* if still no format found, error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 if (!fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 err = AVERROR_NOFMT;
90
27d6df9208d4 merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents: 85
diff changeset
358 goto fail1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 /* XXX: suppress this hack for redirectors */
22
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
362 #ifdef CONFIG_NETWORK
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 if (fmt == &redir_demux) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 err = redir_open(ic_ptr, &ic->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 url_fclose(&ic->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 av_free(ic);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 return err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368 }
11
932b59c66c60 mingw patch by (Bill Eldridge <bill at rfa dot org>)
michaelni
parents: 9
diff changeset
369 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 ic->iformat = fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
373 /* check filename in case of an image number is expected */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
374 if (ic->iformat->flags & AVFMT_NEEDNUMBER) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
375 if (filename_number_test(ic->filename) < 0) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
376 err = AVERROR_NUMEXPECTED;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
377 goto fail1;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
378 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
379 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
380
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 /* allocate private data */
32
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
382 if (fmt->priv_data_size > 0) {
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
383 ic->priv_data = av_mallocz(fmt->priv_data_size);
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
384 if (!ic->priv_data) {
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
385 err = AVERROR_NOMEM;
90
27d6df9208d4 merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents: 85
diff changeset
386 goto fail1;
32
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
387 }
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
388 } else
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
389 ic->priv_data = NULL;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 /* default pts settings is MPEG like */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 av_set_pts_info(ic, 33, 1, 90000);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 err = ic->iformat->read_header(ic, ap);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 if (err < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 goto fail1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 *ic_ptr = ic;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 fail1:
90
27d6df9208d4 merging a small amount of the changes from BroadQ, the rest is either not clean / doesnt apply / or is PS2 specific (someone with a PS2 should merge/send a patch for the later)
michaelni
parents: 85
diff changeset
400 if (!fmt || !(fmt->flags & AVFMT_NOFILE)) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 url_fclose(&ic->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 if (ic) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 av_freep(&ic->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 av_free(ic);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 *ic_ptr = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 return err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 * Read a packet from a media file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 * @param pkt is filled
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 * @return 0 if OK. AVERROR_xxx if error.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 int av_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 AVPacketList *pktl;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 pktl = s->packet_buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 if (pktl) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 /* read packet from packet buffer, if there is data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 *pkt = pktl->pkt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 s->packet_buffer = pktl->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 av_free(pktl);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 return s->iformat->read_packet(s, pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 /* state for codec information */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 #define CSTATE_NOTFOUND 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 #define CSTATE_DECODING 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 #define CSTATE_FOUND 2
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 static int has_codec_parameters(AVCodecContext *enc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 int val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 switch(enc->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 val = enc->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 val = enc->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 val = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 return (val != 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 * Read the beginning of a media file to get stream information. This
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 * is useful for file formats with no headers such as MPEG. This
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 * function also compute the real frame rate in case of mpeg2 repeat
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 * frame mode.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 * @param ic media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 * @return >=0 if OK. AVERROR_xxx if error.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 int av_find_stream_info(AVFormatContext *ic)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 int i, count, ret, got_picture, size, read_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 AVCodec *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 AVPacket *pkt;
7
47e502ac6349 AVVideoFrame -> AVFrame
michaelni
parents: 5
diff changeset
471 AVFrame picture;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 AVPacketList *pktl=NULL, **ppktl;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 short samples[AVCODEC_MAX_AUDIO_FRAME_SIZE / 2];
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
474 uint8_t *ptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 int min_read_size, max_read_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 /* 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
478 Mbits. We read at most 0.2 second of file to find all streams */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480 /* XXX: base it on stream bitrate when possible */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 if (ic->iformat == &mpegts_demux) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 /* maximum number of bytes we accept to read to find all the streams
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 in a file */
127
b7ce3b3dc171 VOB stream patch ba (Brian Foley <bfoley at compsoc dot nuigalway dot ie>)
michaelni
parents: 90
diff changeset
484 min_read_size = 6000000;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 } else {
127
b7ce3b3dc171 VOB stream patch ba (Brian Foley <bfoley at compsoc dot nuigalway dot ie>)
michaelni
parents: 90
diff changeset
486 min_read_size = 250000;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 /* 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
489 max_read_size = min_read_size * 10;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 /* set initial codec state */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 if (has_codec_parameters(&st->codec))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 st->codec_info_state = CSTATE_FOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 st->codec_info_state = CSTATE_NOTFOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 st->codec_info_nb_repeat_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 st->codec_info_nb_real_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502 count = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 read_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 ppktl = &ic->packet_buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506 /* check if one codec still needs to be handled */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509 if (st->codec_info_state != CSTATE_FOUND)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 if (i == ic->nb_streams) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 /* NOTE: if the format has no header, then we need to read
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 some packets to get most of the streams, so we cannot
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 stop here */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 if (!(ic->iformat->flags & AVFMT_NOHEADER) ||
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 read_size >= min_read_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 /* if we found the info for all the codecs, we can stop */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 ret = count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523 /* we did not get all the codec info, but we read too much data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524 if (read_size >= max_read_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525 ret = count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 pktl = av_mallocz(sizeof(AVPacketList));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 if (!pktl) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 ret = AVERROR_NOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 /* add the packet in the buffered packet list */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 *ppktl = pktl;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 ppktl = &pktl->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540 /* NOTE: a new stream can be added there if no header in file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 (AVFMT_NOHEADER) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 pkt = &pktl->pkt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
543 if (ic->iformat->read_packet(ic, pkt) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
544 /* EOF or error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545 ret = -1; /* we could not have all the codec parameters before EOF */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546 if ((ic->iformat->flags & AVFMT_NOHEADER) &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547 i == ic->nb_streams)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
548 ret = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551 read_size += pkt->size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 /* open new codecs */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
554 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 if (st->codec_info_state == CSTATE_NOTFOUND) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557 /* set to found in case of error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 st->codec_info_state = CSTATE_FOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559 codec = avcodec_find_decoder(st->codec.codec_id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560 if (codec) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 if(codec->capabilities & CODEC_CAP_TRUNCATED)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 st->codec.flags |= CODEC_FLAG_TRUNCATED;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564 ret = avcodec_open(&st->codec, codec);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 if (ret >= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 st->codec_info_state = CSTATE_DECODING;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
569 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
570
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571 st = ic->streams[pkt->stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572 if (st->codec_info_state == CSTATE_DECODING) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 /* decode the data and update codec parameters */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 ptr = pkt->data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 size = pkt->size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 switch(st->codec.codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 ret = avcodec_decode_video(&st->codec, &picture,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580 &got_picture, ptr, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 ret = avcodec_decode_audio(&st->codec, samples,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 &got_picture, ptr, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 ret = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590 if (ret < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591 /* if error, simply ignore because another packet
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 may be OK */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 if (got_picture) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 /* we got the parameters - now we can stop
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 examining this stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 /* XXX: add a codec info so that we can decide if
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 the codec can repeat frames */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 if (st->codec.codec_id == CODEC_ID_MPEG1VIDEO &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 ic->iformat != &mpegts_demux &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 st->codec.sub_id == 2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 /* for mpeg2 video, we want to know the real
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 frame rate, so we decode 40 frames. In mpeg
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
605 TS case we do not do it because it would be
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606 too long */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607 st->codec_info_nb_real_frames++;
70
e851fa232508 move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents: 65
diff changeset
608 st->codec_info_nb_repeat_frames += st->codec.coded_frame->repeat_pict;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
610 /* XXX: testing */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 if ((st->codec_info_nb_real_frames % 24) == 23) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 st->codec_info_nb_repeat_frames += 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 /* stop after 40 frames */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616 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
617 av_reduce(
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
618 &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
619 &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
620 (int64_t)st->codec.frame_rate * st->codec_info_nb_real_frames,
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
621 st->codec_info_nb_real_frames + (st->codec_info_nb_repeat_frames >> 1),
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
622 1<<30);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 goto close_codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
625 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626 close_codec:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 st->codec_info_state = CSTATE_FOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 avcodec_close(&st->codec);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
631 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632 ptr += ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
633 size -= ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
634 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 count++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 /* close each codec if there are opened */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642 if (st->codec_info_state == CSTATE_DECODING)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 avcodec_close(&st->codec);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
645
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
646 /* set real frame rate info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
649 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
650 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
651 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
652 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
653 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
655 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
660 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
661 * Close a media file (but not its codecs)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
662 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
665 void av_close_input_file(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
668
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
669 if (s->iformat->read_close)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
670 s->iformat->read_close(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
671 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
672 av_free(s->streams[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
673 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674 if (s->packet_buffer) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
675 AVPacketList *p, *p1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676 p = s->packet_buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
677 while (p != NULL) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
678 p1 = p->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
679 av_free_packet(&p->pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
680 av_free(p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
681 p = p1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
682 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
683 s->packet_buffer = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
684 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
685 if (!(s->iformat->flags & AVFMT_NOFILE)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
686 url_fclose(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
687 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 av_freep(&s->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
689 av_free(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
690 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
691
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
692 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
693 * Add a new stream to a media file. Can only be called in the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
694 * read_header function. If the flag AVFMT_NOHEADER is in the format
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
695 * description, then new streams can be added in read_packet too.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
696 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
697 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
698 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
699 * @param id file format dependent stream id
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
700 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
701 AVStream *av_new_stream(AVFormatContext *s, int id)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
703 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
704
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
705 if (s->nb_streams >= MAX_STREAMS)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
706 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
707
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
708 st = av_mallocz(sizeof(AVStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710 return NULL;
5
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
711 avcodec_get_context_defaults(&st->codec);
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
712
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
713 st->index = s->nb_streams;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714 st->id = id;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715 s->streams[s->nb_streams++] = st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716 return st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
718
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719 /************************************************************/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720 /* output media file */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
722 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
723 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
724 int ret;
32
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
725
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
726 if (s->oformat->priv_data_size > 0) {
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
727 s->priv_data = av_mallocz(s->oformat->priv_data_size);
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
728 if (!s->priv_data)
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
729 return AVERROR_NOMEM;
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
730 } else
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
731 s->priv_data = NULL;
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
732
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
733 if (s->oformat->set_parameters) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
734 ret = s->oformat->set_parameters(s, ap);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
735 if (ret < 0)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
736 return ret;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
737 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
738 return 0;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
739 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
740
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
741 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
742 * allocate the stream private data and write the stream header to an
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
743 * output media file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
744 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
746 * @return 0 if OK. AVERROR_xxx if error.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
747 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
748 int av_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
749 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
750 int ret, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
751 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
752
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
753 /* default pts settings is MPEG like */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
754 av_set_pts_info(s, 33, 1, 90000);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
755 ret = s->oformat->write_header(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
756 if (ret < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
757 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
758
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
759 /* init PTS generation */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
761 st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
763 switch (st->codec.codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765 av_frac_init(&st->pts, 0, 0,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
766 (int64_t)s->pts_num * st->codec.sample_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
768 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 av_frac_init(&st->pts, 0, 0,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
770 (int64_t)s->pts_num * st->codec.frame_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
771 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
773 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
775 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
776 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
777 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
778
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
779 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
780 * Write a packet to an output media file. The packet shall contain
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
781 * one audio or video frame.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
782 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
783 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
784 * @param stream_index stream index
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
785 * @param buf buffer containing the frame data
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
786 * @param size size of buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
787 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
788 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
789 int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
790 int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
791 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
792 AVStream *st;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
793 int64_t pts_mask;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
794 int ret, frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
795
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
796 st = s->streams[stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
797 pts_mask = (1LL << s->pts_wrap_bits) - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
798 ret = s->oformat->write_packet(s, stream_index, (uint8_t *)buf, size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799 st->pts.val & pts_mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
800 if (ret < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
801 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
802
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
803 /* update pts */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
804 switch (st->codec.codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
805 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
806 if (st->codec.frame_size <= 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
807 frame_size = size / st->codec.channels;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
808 /* specific hack for pcm codecs because no frame size is provided */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
809 switch(st->codec.codec_id) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
810 case CODEC_ID_PCM_S16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
811 case CODEC_ID_PCM_S16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
812 case CODEC_ID_PCM_U16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
813 case CODEC_ID_PCM_U16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
814 frame_size >>= 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
815 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
816 default:
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 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
820 frame_size = st->codec.frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
821 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
822 av_frac_add(&st->pts,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
823 (int64_t)s->pts_den * frame_size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
824 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
825 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
826 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
827 (int64_t)s->pts_den * st->codec.frame_rate_base);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
828 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
829 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
830 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
831 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
832 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
833 }
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 * write the stream trailer to an output media file and and free the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
837 * file private data.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
838 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
840 * @return 0 if OK. AVERROR_xxx if error. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841 int av_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
842 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
843 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
844 ret = s->oformat->write_trailer(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
845 av_freep(&s->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
846 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
847 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
848
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
849 /* "user interface" functions */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
850
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
851 void dump_format(AVFormatContext *ic,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
852 int index,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
853 const char *url,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
854 int is_output)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
855 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
856 int i, flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
857 char buf[256];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
858
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
859 fprintf(stderr, "%s #%d, %s, %s '%s':\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
860 is_output ? "Output" : "Input",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
861 index,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
862 is_output ? ic->oformat->name : ic->iformat->name,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
863 is_output ? "to" : "from", url);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
864 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
865 AVStream *st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
866 avcodec_string(buf, sizeof(buf), &st->codec, is_output);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
867 fprintf(stderr, " Stream #%d.%d", index, i);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
868 /* the pid is an important information, so we display it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
869 /* XXX: add a generic system */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
870 if (is_output)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
871 flags = ic->oformat->flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
872 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
873 flags = ic->iformat->flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
874 if (flags & AVFMT_SHOW_IDS) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
875 fprintf(stderr, "[0x%x]", st->id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
876 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
877 fprintf(stderr, ": %s\n", buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
878 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
879 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
880
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
881 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
882 const char *str;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
883 int width, height;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
884 } SizeEntry;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
885
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
886 static SizeEntry sizes[] = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
887 { "sqcif", 128, 96 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
888 { "qcif", 176, 144 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
889 { "cif", 352, 288 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
890 { "4cif", 704, 576 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
891 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
892
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
893 int parse_image_size(int *width_ptr, int *height_ptr, const char *str)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
894 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
895 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
896 int n = sizeof(sizes) / sizeof(SizeEntry);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
897 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
898 int frame_width = 0, frame_height = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
899
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
900 for(i=0;i<n;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
901 if (!strcmp(sizes[i].str, str)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
902 frame_width = sizes[i].width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
903 frame_height = sizes[i].height;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
904 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
905 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
906 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
907 if (i == n) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
908 p = str;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
909 frame_width = strtol(p, (char **)&p, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
910 if (*p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
911 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
912 frame_height = strtol(p, (char **)&p, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
913 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
914 if (frame_width <= 0 || frame_height <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
915 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
916 *width_ptr = frame_width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
917 *height_ptr = frame_height;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
918 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
919 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
920
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
921 int64_t av_gettime(void)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
922 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
923 #ifdef CONFIG_WIN32
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
924 struct _timeb tb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
925 _ftime(&tb);
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
926 return ((int64_t)tb.time * int64_t_C(1000) + (int64_t)tb.millitm) * int64_t_C(1000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
927 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
928 struct timeval tv;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
929 gettimeofday(&tv,NULL);
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
930 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
931 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
932 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
933
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
934 static time_t mktimegm(struct tm *tm)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
935 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
936 time_t t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
937
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
938 int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
939
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
940 if (m < 3) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
941 m += 12;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
942 y--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
943 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
944
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
945 t = 86400 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
946 (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
947
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
948 t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
949
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
950 return t;
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 /* Syntax:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
954 * - If not a duration:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
955 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
956 * Time is localtime unless Z is suffixed to the end. In this case GMT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
957 * Return the date in micro seconds since 1970
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
958 * - If duration:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
959 * HH[:MM[:SS[.m...]]]
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
960 * S+[.m...]
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
961 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
962 int64_t parse_date(const char *datestr, int duration)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
963 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
964 const char *p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
965 int64_t t;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
966 struct tm dt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
967 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
968 static const char *date_fmt[] = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
969 "%Y-%m-%d",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
970 "%Y%m%d",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
971 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
972 static const char *time_fmt[] = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
973 "%H:%M:%S",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
974 "%H%M%S",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
975 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
976 const char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
977 int is_utc, len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
978 char lastch;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
979 time_t now = time(0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
980
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
981 len = strlen(datestr);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
982 if (len > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
983 lastch = datestr[len - 1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
984 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
985 lastch = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
986 is_utc = (lastch == 'z' || lastch == 'Z');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
987
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
988 memset(&dt, 0, sizeof(dt));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
989
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
990 p = datestr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
991 q = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
992 if (!duration) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
993 for (i = 0; i < sizeof(date_fmt) / sizeof(date_fmt[0]); i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
994 q = strptime(p, date_fmt[i], &dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
995 if (q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
996 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
997 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
998 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
999
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1000 if (!q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1001 if (is_utc) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1002 dt = *gmtime(&now);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1003 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1004 dt = *localtime(&now);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1005 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1006 dt.tm_hour = dt.tm_min = dt.tm_sec = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1007 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1008 p = q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1009 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1010
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1011 if (*p == 'T' || *p == 't' || *p == ' ')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1012 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1013
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1014 for (i = 0; i < sizeof(time_fmt) / sizeof(time_fmt[0]); i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1015 q = strptime(p, time_fmt[i], &dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1016 if (q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1017 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1018 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1019 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1020 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1021 q = strptime(p, time_fmt[0], &dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1022 if (!q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1023 dt.tm_sec = strtol(p, (char **)&q, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1024 dt.tm_min = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1025 dt.tm_hour = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1026 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1027 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1028
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1029 /* Now we have all the fields that we can get */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1030 if (!q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1031 if (duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1032 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1033 else
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1034 return now * int64_t_C(1000000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1035 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1036
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1037 if (duration) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1038 t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1039 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1040 dt.tm_isdst = -1; /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1041 if (is_utc) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1042 t = mktimegm(&dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1043 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1044 t = mktime(&dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1045 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1046 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1047
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1048 t *= 1000000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1049
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1050 if (*q == '.') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1051 int val, n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1052 q++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1053 for (val = 0, n = 100000; n >= 1; n /= 10, q++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1054 if (!isdigit(*q))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1055 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1056 val += n * (*q - '0');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1057 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1058 t += val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1059 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1060 return t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1061 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1062
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1063 /* syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. Return
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1064 1 if found */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1065 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1066 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1067 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1068 char tag[128], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1069
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1070 p = info;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1071 if (*p == '?')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1072 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1073 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1074 q = tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1075 while (*p != '\0' && *p != '=' && *p != '&') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1076 if ((q - tag) < sizeof(tag) - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1077 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1078 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1079 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1080 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1081 q = arg;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1082 if (*p == '=') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1083 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1084 while (*p != '&' && *p != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1085 if ((q - arg) < arg_size - 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1086 if (*p == '+')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1087 *q++ = ' ';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1088 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1089 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1090 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1091 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1092 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1093 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1094 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1095 if (!strcmp(tag, tag1))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1096 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1097 if (*p != '&')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1098 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1099 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1100 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1101 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1102 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1103
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1104 /* Return in 'buf' the path with '%d' replaced by number. Also handles
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1105 the '%0nd' format where 'n' is the total number of digits and
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1106 '%%'. Return 0 if OK, and -1 if format error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1107 int get_frame_filename(char *buf, int buf_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1108 const char *path, int number)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1109 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1110 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1111 char *q, buf1[20];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1112 int nd, len, c, percentd_found;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1113
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1114 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1115 p = path;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1116 percentd_found = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1117 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1118 c = *p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1119 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1120 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1121 if (c == '%') {
9
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1122 do {
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1123 nd = 0;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1124 while (isdigit(*p)) {
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1125 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
1126 }
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1127 c = *p++;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1128 if (c == '*' && nd > 0) {
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1129 // The nd field is actually the modulus
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1130 number = number % nd;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1131 c = *p++;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1132 nd = 0;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1133 }
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1134 } while (isdigit(c));
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1135
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1136 switch(c) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1137 case '%':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1138 goto addchar;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1139 case 'd':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1140 if (percentd_found)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1141 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1142 percentd_found = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1143 snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1144 len = strlen(buf1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1145 if ((q - buf + len) > buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1146 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1147 memcpy(q, buf1, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1148 q += len;
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 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1152 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1153 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1154 addchar:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1155 if ((q - buf) < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1156 *q++ = c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1157 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1158 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1159 if (!percentd_found)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1160 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1161 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1162 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1163 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1164 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1165 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1166 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1167
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 * Print on stdout a nice hexa dump of a buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1171 * @param buf buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1172 * @param size buffer size
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1173 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1174 void av_hex_dump(uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1175 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1176 int len, i, j, c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1177
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1178 for(i=0;i<size;i+=16) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1179 len = size - i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1180 if (len > 16)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1181 len = 16;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1182 printf("%08x ", i);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1183 for(j=0;j<16;j++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1184 if (j < len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1185 printf(" %02x", buf[i+j]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1186 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1187 printf(" ");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1188 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1189 printf(" ");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1190 for(j=0;j<len;j++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1191 c = buf[i+j];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1192 if (c < ' ' || c > '~')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1193 c = '.';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1194 printf("%c", c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1195 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1196 printf("\n");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1197 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1198 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1200 void url_split(char *proto, int proto_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1201 char *hostname, int hostname_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1202 int *port_ptr,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1203 char *path, int path_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1204 const char *url)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1205 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1206 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1207 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1208 int port;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1209
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1210 port = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1211
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1212 p = url;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1213 q = proto;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1214 while (*p != ':' && *p != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1215 if ((q - proto) < proto_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1216 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1217 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1218 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1219 if (proto_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1220 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1221 if (*p == '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1222 if (proto_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1223 proto[0] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1224 if (hostname_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1225 hostname[0] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1226 p = url;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1227 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1228 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1229 if (*p == '/')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1230 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1231 if (*p == '/')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1232 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1233 q = hostname;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1234 while (*p != ':' && *p != '/' && *p != '?' && *p != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1235 if ((q - hostname) < hostname_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1236 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1237 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1238 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1239 if (hostname_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1240 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1241 if (*p == ':') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1242 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1243 port = strtoul(p, (char **)&p, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1244 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1245 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1246 if (port_ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1247 *port_ptr = port;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1248 pstrcpy(path, path_size, p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1249 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1250
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1251 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1252 * Set the pts for a given stream
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1253 * @param s stream
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1254 * @param pts_wrap_bits number of bits effectively used by the pts
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1255 * (used for wrap control, 33 is the value for MPEG)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1256 * @param pts_num numerator to convert to seconds (MPEG: 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1257 * @param pts_den denominator to convert to seconds (MPEG: 90000)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1258 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1259 void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1260 int pts_num, int pts_den)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1261 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1262 s->pts_wrap_bits = pts_wrap_bits;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1263 s->pts_num = pts_num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1264 s->pts_den = pts_den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1265 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1266
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1267 /* fraction handling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1268
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1269 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1270 * f = val + (num / den) + 0.5. 'num' is normalized so that it is such
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1271 * as 0 <= num < den.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1272 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1273 * @param f fractional number
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1274 * @param val integer value
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1275 * @param num must be >= 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1276 * @param den must be >= 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1277 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1278 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
1279 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1280 num += (den >> 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1281 if (num >= den) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1282 val += num / den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1283 num = num % den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1284 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1285 f->val = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1286 f->num = num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1287 f->den = den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1288 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1289
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1290 /* set f to (val + 0.5) */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1291 void av_frac_set(AVFrac *f, int64_t val)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1292 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1293 f->val = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1294 f->num = f->den >> 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1295 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1296
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1297 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1298 * Fractionnal addition to f: f = f + (incr / f->den)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1299 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1300 * @param f fractional number
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1301 * @param incr increment, can be positive or negative
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1302 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1303 void av_frac_add(AVFrac *f, int64_t incr)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1304 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1305 int64_t num, den;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1306
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1307 num = f->num + incr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1308 den = f->den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1309 if (num < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1310 f->val += num / den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1311 num = num % den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1312 if (num < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1313 num += den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1314 f->val--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1315 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1316 } else if (num >= den) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1317 f->val += num / den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1318 num = num % den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1319 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1320 f->num = num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1321 }
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1322
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1323 /**
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1324 * register a new image format
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1325 * @param img_fmt Image format descriptor
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1326 */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1327 void av_register_image_format(AVImageFormat *img_fmt)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1328 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1329 AVImageFormat **p;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1330
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1331 p = &first_image_format;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1332 while (*p != NULL) p = &(*p)->next;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1333 *p = img_fmt;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1334 img_fmt->next = NULL;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1335 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1336
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1337 /* guess image format */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1338 AVImageFormat *av_probe_image_format(AVProbeData *pd)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1339 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1340 AVImageFormat *fmt1, *fmt;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1341 int score, score_max;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1342
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1343 fmt = NULL;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1344 score_max = 0;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1345 for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1346 if (fmt1->img_probe) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1347 score = fmt1->img_probe(pd);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1348 if (score > score_max) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1349 score_max = score;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1350 fmt = fmt1;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1351 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1352 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1353 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1354 return fmt;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1355 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1356
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1357 AVImageFormat *guess_image_format(const char *filename)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1358 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1359 AVImageFormat *fmt1;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1360
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1361 for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1362 if (fmt1->extensions && match_ext(filename, fmt1->extensions))
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1363 return fmt1;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1364 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1365 return NULL;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1366 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1367
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1368 /**
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1369 * Read an image from a stream.
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1370 * @param gb byte stream containing the image
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1371 * @param fmt image format, NULL if probing is required
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1372 */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1373 int av_read_image(ByteIOContext *pb, const char *filename,
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1374 AVImageFormat *fmt,
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1375 int (*alloc_cb)(void *, AVImageInfo *info), void *opaque)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1376 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1377 char buf[PROBE_BUF_SIZE];
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1378 AVProbeData probe_data, *pd = &probe_data;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1379 offset_t pos;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1380 int ret;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1381
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1382 if (!fmt) {
64
b0e0eb595e29 * static,const,compiler warning cleanup
kabi
parents: 53
diff changeset
1383 pd->filename = filename;
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1384 pd->buf = buf;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1385 pos = url_ftell(pb);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1386 pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1387 url_fseek(pb, pos, SEEK_SET);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1388 fmt = av_probe_image_format(pd);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1389 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1390 if (!fmt)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1391 return AVERROR_NOFMT;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1392 ret = fmt->img_read(pb, alloc_cb, opaque);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1393 return ret;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1394 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1395
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1396 /**
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1397 * Write an image to a stream.
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1398 * @param pb byte stream for the image output
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1399 * @param fmt image format
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1400 * @param img image data and informations
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1401 */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1402 int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1403 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1404 return fmt->img_write(pb, img);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1405 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1406