annotate utils.c @ 180:9e673f620f4d libavformat

support aborting in TCP
author bellard
date Thu, 17 Jul 2003 10:28:27 +0000
parents b6fa8a3b78c6
children 0316a506aeb0
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;
172
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
315 int err, must_open_file;
0
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
172
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
334 /* do not open file if the format does not need it. XXX: specific
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
335 hack needed to handle RTSP/TCP */
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
336 must_open_file = 1;
175
b6fa8a3b78c6 fix fmt == NULL case
bellard
parents: 172
diff changeset
337 if ((fmt && (fmt->flags & AVFMT_NOFILE)) ||
172
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
338 (fmt == &rtp_demux && !strcmp(filename, "null"))) {
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
339 must_open_file = 0;
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
340 }
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
341
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
342 if (!fmt || must_open_file) {
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
343 /* if no file needed do not try to open one */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 if (url_fopen(&ic->pb, filename, URL_RDONLY) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 err = AVERROR_IO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 if (buf_size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 url_setbufsize(&ic->pb, buf_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 if (!fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 /* read probe data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 pd->buf_size = get_buffer(&ic->pb, buf, PROBE_BUF_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 url_fseek(&ic->pb, 0, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 /* guess file format */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 if (!fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 fmt = av_probe_input_format(pd, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 /* if still no format found, error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 if (!fmt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 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
366 goto fail1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 /* XXX: suppress this hack for redirectors */
22
65433f1b2549 os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 21
diff changeset
370 #ifdef CONFIG_NETWORK
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 if (fmt == &redir_demux) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 err = redir_open(ic_ptr, &ic->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 url_fclose(&ic->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 av_free(ic);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 return err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 }
11
932b59c66c60 mingw patch by (Bill Eldridge <bill at rfa dot org>)
michaelni
parents: 9
diff changeset
377 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 ic->iformat = fmt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
381 /* check filename in case of an image number is expected */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
382 if (ic->iformat->flags & AVFMT_NEEDNUMBER) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
383 if (filename_number_test(ic->filename) < 0) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
384 err = AVERROR_NUMEXPECTED;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
385 goto fail1;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
386 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
387 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
388
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 /* allocate private data */
32
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
390 if (fmt->priv_data_size > 0) {
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
391 ic->priv_data = av_mallocz(fmt->priv_data_size);
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
392 if (!ic->priv_data) {
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
393 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
394 goto fail1;
32
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
395 }
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
396 } else
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
397 ic->priv_data = NULL;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 /* default pts settings is MPEG like */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 av_set_pts_info(ic, 33, 1, 90000);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 err = ic->iformat->read_header(ic, ap);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 if (err < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 goto fail1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 *ic_ptr = ic;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 fail1:
172
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
408 if (!fmt || must_open_file) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 url_fclose(&ic->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 if (ic) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 av_freep(&ic->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 av_free(ic);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 *ic_ptr = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 return err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 * Read a packet from a media file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 * @param pkt is filled
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 * @return 0 if OK. AVERROR_xxx if error.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 int av_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 AVPacketList *pktl;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 pktl = s->packet_buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 if (pktl) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 /* read packet from packet buffer, if there is data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 *pkt = pktl->pkt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 s->packet_buffer = pktl->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 av_free(pktl);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 return s->iformat->read_packet(s, pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 /* state for codec information */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 #define CSTATE_NOTFOUND 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 #define CSTATE_DECODING 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 #define CSTATE_FOUND 2
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 static int has_codec_parameters(AVCodecContext *enc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 int val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 switch(enc->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 val = enc->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 val = enc->width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 val = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 return (val != 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 * Read the beginning of a media file to get stream information. This
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 * is useful for file formats with no headers such as MPEG. This
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 * function also compute the real frame rate in case of mpeg2 repeat
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 * frame mode.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 * @param ic media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 * @return >=0 if OK. AVERROR_xxx if error.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 int av_find_stream_info(AVFormatContext *ic)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 int i, count, ret, got_picture, size, read_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 AVCodec *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 AVPacket *pkt;
7
47e502ac6349 AVVideoFrame -> AVFrame
michaelni
parents: 5
diff changeset
479 AVFrame picture;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480 AVPacketList *pktl=NULL, **ppktl;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 short samples[AVCODEC_MAX_AUDIO_FRAME_SIZE / 2];
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
482 uint8_t *ptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 int min_read_size, max_read_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 /* 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
486 Mbits. We read at most 0.2 second of file to find all streams */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 /* XXX: base it on stream bitrate when possible */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 if (ic->iformat == &mpegts_demux) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 /* maximum number of bytes we accept to read to find all the streams
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 in a file */
127
b7ce3b3dc171 VOB stream patch ba (Brian Foley <bfoley at compsoc dot nuigalway dot ie>)
michaelni
parents: 90
diff changeset
492 min_read_size = 6000000;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 } else {
127
b7ce3b3dc171 VOB stream patch ba (Brian Foley <bfoley at compsoc dot nuigalway dot ie>)
michaelni
parents: 90
diff changeset
494 min_read_size = 250000;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 /* 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
497 max_read_size = min_read_size * 10;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 /* set initial codec state */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502 if (has_codec_parameters(&st->codec))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 st->codec_info_state = CSTATE_FOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505 st->codec_info_state = CSTATE_NOTFOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506 st->codec_info_nb_repeat_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507 st->codec_info_nb_real_frames = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 count = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 read_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 ppktl = &ic->packet_buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 /* check if one codec still needs to be handled */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 if (st->codec_info_state != CSTATE_FOUND)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 if (i == ic->nb_streams) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 /* NOTE: if the format has no header, then we need to read
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 some packets to get most of the streams, so we cannot
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523 stop here */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524 if (!(ic->iformat->flags & AVFMT_NOHEADER) ||
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525 read_size >= min_read_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 /* if we found the info for all the codecs, we can stop */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 ret = count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 /* we did not get all the codec info, but we read too much data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 if (read_size >= max_read_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 ret = count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 pktl = av_mallocz(sizeof(AVPacketList));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 if (!pktl) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540 ret = AVERROR_NOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
543
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
544 /* add the packet in the buffered packet list */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545 *ppktl = pktl;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546 ppktl = &pktl->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
548 /* NOTE: a new stream can be added there if no header in file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549 (AVFMT_NOHEADER) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550 pkt = &pktl->pkt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551 if (ic->iformat->read_packet(ic, pkt) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552 /* EOF or error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 ret = -1; /* we could not have all the codec parameters before EOF */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
554 if ((ic->iformat->flags & AVFMT_NOHEADER) &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555 i == ic->nb_streams)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 ret = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559 read_size += pkt->size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 /* open new codecs */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564 if (st->codec_info_state == CSTATE_NOTFOUND) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 /* set to found in case of error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 st->codec_info_state = CSTATE_FOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 codec = avcodec_find_decoder(st->codec.codec_id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568 if (codec) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
569 if(codec->capabilities & CODEC_CAP_TRUNCATED)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
570 st->codec.flags |= CODEC_FLAG_TRUNCATED;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572 ret = avcodec_open(&st->codec, codec);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 if (ret >= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 st->codec_info_state = CSTATE_DECODING;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 st = ic->streams[pkt->stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580 if (st->codec_info_state == CSTATE_DECODING) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 /* decode the data and update codec parameters */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582 ptr = pkt->data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 size = pkt->size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 switch(st->codec.codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 ret = avcodec_decode_video(&st->codec, &picture,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 &got_picture, ptr, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591 ret = avcodec_decode_audio(&st->codec, samples,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 &got_picture, ptr, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 ret = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 if (ret < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 /* if error, simply ignore because another packet
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 may be OK */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 if (got_picture) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604 /* we got the parameters - now we can stop
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
605 examining this stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606 /* XXX: add a codec info so that we can decide if
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607 the codec can repeat frames */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608 if (st->codec.codec_id == CODEC_ID_MPEG1VIDEO &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 ic->iformat != &mpegts_demux &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
610 st->codec.sub_id == 2) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 /* for mpeg2 video, we want to know the real
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 frame rate, so we decode 40 frames. In mpeg
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 TS case we do not do it because it would be
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 too long */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 st->codec_info_nb_real_frames++;
70
e851fa232508 move repeat_pict field from AVCodecContext -> AVFrame (closes bug #683536)
michaelni
parents: 65
diff changeset
616 st->codec_info_nb_repeat_frames += st->codec.coded_frame->repeat_pict;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618 /* XXX: testing */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619 if ((st->codec_info_nb_real_frames % 24) == 23) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
620 st->codec_info_nb_repeat_frames += 2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
621 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 /* stop after 40 frames */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624 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
625 av_reduce(
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
626 &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
627 &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
628 (int64_t)st->codec.frame_rate * st->codec_info_nb_real_frames,
162
35386fc4d47d mpeg1 bad frame_rate_base fix by (Arthur van Hoff (javanator))
michaelni
parents: 127
diff changeset
629 (st->codec_info_nb_real_frames + (st->codec_info_nb_repeat_frames >> 1)) * st->codec.frame_rate_base,
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 75
diff changeset
630 1<<30);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
631 goto close_codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
633 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
634 close_codec:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 st->codec_info_state = CSTATE_FOUND;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 avcodec_close(&st->codec);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640 ptr += ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 size -= ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644 count++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
645 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
646
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647 /* close each codec if there are opened */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
649 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
650 if (st->codec_info_state == CSTATE_DECODING)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
651 avcodec_close(&st->codec);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
652 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
653
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654 /* set real frame rate info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
655 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657 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
658 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
659 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
660 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
661 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
662 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
665 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
668 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
669 * Close a media file (but not its codecs)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
670 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
671 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
672 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
673 void av_close_input_file(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674 {
172
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
675 int i, must_open_file;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
677 if (s->iformat->read_close)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
678 s->iformat->read_close(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
679 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
680 av_free(s->streams[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
681 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
682 if (s->packet_buffer) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
683 AVPacketList *p, *p1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
684 p = s->packet_buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
685 while (p != NULL) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
686 p1 = p->next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
687 av_free_packet(&p->pkt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 av_free(p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
689 p = p1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
690 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
691 s->packet_buffer = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
692 }
172
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
693 must_open_file = 1;
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
694 if ((s->iformat->flags & AVFMT_NOFILE) ||
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
695 (s->iformat == &rtp_demux && !strcmp(s->filename, "null"))) {
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
696 must_open_file = 0;
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
697 }
9a0ab557b159 fixed RTP/TCP client support
bellard
parents: 168
diff changeset
698 if (must_open_file) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
699 url_fclose(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
700 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
701 av_freep(&s->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702 av_free(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
703 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
704
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
705 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
706 * Add a new stream to a media file. Can only be called in the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
707 * read_header function. If the flag AVFMT_NOHEADER is in the format
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
708 * description, then new streams can be added in read_packet too.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
711 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
712 * @param id file format dependent stream id
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
713 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714 AVStream *av_new_stream(AVFormatContext *s, int id)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
718 if (s->nb_streams >= MAX_STREAMS)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719 return NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721 st = av_mallocz(sizeof(AVStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
723 return NULL;
5
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
724 avcodec_get_context_defaults(&st->codec);
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
725
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
726 st->index = s->nb_streams;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727 st->id = id;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728 s->streams[s->nb_streams++] = st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 return st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
730 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
731
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
732 /************************************************************/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
733 /* output media file */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
734
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
735 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
736 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
737 int ret;
32
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
738
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
739 if (s->oformat->priv_data_size > 0) {
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
740 s->priv_data = av_mallocz(s->oformat->priv_data_size);
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
741 if (!s->priv_data)
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
742 return AVERROR_NOMEM;
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
743 } else
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
744 s->priv_data = NULL;
cd0155c9022e zero sized malloc patch by Roman Shaposhnick
bellard
parents: 30
diff changeset
745
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
746 if (s->oformat->set_parameters) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
747 ret = s->oformat->set_parameters(s, ap);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
748 if (ret < 0)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
749 return ret;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
750 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
751 return 0;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
752 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
753
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
754 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
755 * allocate the stream private data and write the stream header to an
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
756 * output media file
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
757 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
758 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
759 * @return 0 if OK. AVERROR_xxx if error.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
761 int av_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
763 int ret, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
766 /* default pts settings is MPEG like */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 av_set_pts_info(s, 33, 1, 90000);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
768 ret = s->oformat->write_header(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 if (ret < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
770 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
771
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772 /* init PTS generation */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
773 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774 st = s->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
775
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
776 switch (st->codec.codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
777 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
778 av_frac_init(&st->pts, 0, 0,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
779 (int64_t)s->pts_num * st->codec.sample_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
780 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
781 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
782 av_frac_init(&st->pts, 0, 0,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
783 (int64_t)s->pts_num * st->codec.frame_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
784 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
785 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
786 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
787 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
788 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
789 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
790 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
791
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
792 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
793 * Write a packet to an output media file. The packet shall contain
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
794 * one audio or video frame.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
795 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
796 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
797 * @param stream_index stream index
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
798 * @param buf buffer containing the frame data
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799 * @param size size of buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
800 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
801 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
802 int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
803 int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
804 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
805 AVStream *st;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
806 int64_t pts_mask;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
807 int ret, frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
808
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
809 st = s->streams[stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
810 pts_mask = (1LL << s->pts_wrap_bits) - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
811 ret = s->oformat->write_packet(s, stream_index, (uint8_t *)buf, size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
812 st->pts.val & pts_mask);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
813 if (ret < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
814 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
815
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
816 /* update pts */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
817 switch (st->codec.codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
818 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
819 if (st->codec.frame_size <= 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
820 frame_size = size / st->codec.channels;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
821 /* specific hack for pcm codecs because no frame size is provided */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
822 switch(st->codec.codec_id) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
823 case CODEC_ID_PCM_S16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
824 case CODEC_ID_PCM_S16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
825 case CODEC_ID_PCM_U16LE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
826 case CODEC_ID_PCM_U16BE:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
827 frame_size >>= 1;
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 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
833 frame_size = st->codec.frame_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
834 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
835 av_frac_add(&st->pts,
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
836 (int64_t)s->pts_den * frame_size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
837 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
838 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839 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
840 (int64_t)s->pts_den * st->codec.frame_rate_base);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
842 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
843 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
844 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
845 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
846 }
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 * write the stream trailer to an output media file and and free the
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
850 * file private data.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
851 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
852 * @param s media file handle
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
853 * @return 0 if OK. AVERROR_xxx if error. */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
854 int av_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
855 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
856 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
857 ret = s->oformat->write_trailer(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
858 av_freep(&s->priv_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
859 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
860 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
861
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
862 /* "user interface" functions */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
863
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
864 void dump_format(AVFormatContext *ic,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
865 int index,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
866 const char *url,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
867 int is_output)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
868 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
869 int i, flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
870 char buf[256];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
871
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
872 fprintf(stderr, "%s #%d, %s, %s '%s':\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
873 is_output ? "Output" : "Input",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
874 index,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
875 is_output ? ic->oformat->name : ic->iformat->name,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
876 is_output ? "to" : "from", url);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
877 for(i=0;i<ic->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
878 AVStream *st = ic->streams[i];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
879 avcodec_string(buf, sizeof(buf), &st->codec, is_output);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
880 fprintf(stderr, " Stream #%d.%d", index, i);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
881 /* the pid is an important information, so we display it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
882 /* XXX: add a generic system */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
883 if (is_output)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
884 flags = ic->oformat->flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
885 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
886 flags = ic->iformat->flags;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
887 if (flags & AVFMT_SHOW_IDS) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
888 fprintf(stderr, "[0x%x]", st->id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
889 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
890 fprintf(stderr, ": %s\n", buf);
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
894 typedef struct {
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
895 const char *abv;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
896 int width, height;
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
897 int frame_rate, frame_rate_base;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
898 } AbvEntry;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
899
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
900 static AbvEntry frame_abvs[] = {
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
901 { "ntsc", 352, 240, 30000, 1001 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
902 { "pal", 352, 288, 25, 1 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
903 { "film", 352, 240, 24, 1 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
904 { "ntsc-film", 352, 240, 24000, 1001 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
905 { "sqcif", 128, 96, 0, 0 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
906 { "qcif", 176, 144, 0, 0 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
907 { "cif", 352, 288, 0, 0 },
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
908 { "4cif", 704, 576, 0, 0 },
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
909 };
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
910
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
911 int parse_image_size(int *width_ptr, int *height_ptr, const char *str)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
912 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
913 int i;
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
914 int n = sizeof(frame_abvs) / sizeof(AbvEntry);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
915 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
916 int frame_width = 0, frame_height = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
917
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
918 for(i=0;i<n;i++) {
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
919 if (!strcmp(frame_abvs[i].abv, str)) {
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
920 frame_width = frame_abvs[i].width;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
921 frame_height = frame_abvs[i].height;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
922 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
923 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
924 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
925 if (i == n) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
926 p = str;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
927 frame_width = strtol(p, (char **)&p, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
928 if (*p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
929 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
930 frame_height = strtol(p, (char **)&p, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
931 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
932 if (frame_width <= 0 || frame_height <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
933 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
934 *width_ptr = frame_width;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
935 *height_ptr = frame_height;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
936 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
937 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
938
168
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
939 int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg)
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
940 {
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
941 int i;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
942 char* cp;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
943
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
944 /* First, we check our abbreviation table */
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
945 for (i = 0; i < sizeof(frame_abvs)/sizeof(*frame_abvs); ++i)
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
946 if (!strcmp(frame_abvs[i].abv, arg)) {
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
947 *frame_rate = frame_abvs[i].frame_rate;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
948 *frame_rate_base = frame_abvs[i].frame_rate_base;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
949 return 0;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
950 }
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
951
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
952 /* Then, we try to parse it as fraction */
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
953 cp = strchr(arg, '/');
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
954 if (cp) {
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
955 char* cpp;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
956 *frame_rate = strtol(arg, &cpp, 10);
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
957 if (cpp != arg || cpp == cp)
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
958 *frame_rate_base = strtol(cp+1, &cpp, 10);
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
959 else
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
960 *frame_rate = 0;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
961 }
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
962 else {
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
963 /* Finally we give up and parse it as double */
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
964 *frame_rate_base = DEFAULT_FRAME_RATE_BASE;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
965 *frame_rate = (int)(strtod(arg, 0) * (*frame_rate_base) + 0.5);
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
966 }
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
967 if (!*frame_rate || !*frame_rate_base)
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
968 return -1;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
969 else
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
970 return 0;
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
971 }
808dabf5a88e * First round of AV sync fixes.
romansh
parents: 162
diff changeset
972
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
973 int64_t av_gettime(void)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
974 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
975 #ifdef CONFIG_WIN32
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
976 struct _timeb tb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
977 _ftime(&tb);
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
978 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
979 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
980 struct timeval tv;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
981 gettimeofday(&tv,NULL);
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
982 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
983 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
984 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
985
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
986 static time_t mktimegm(struct tm *tm)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
987 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
988 time_t t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
989
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
990 int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
991
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
992 if (m < 3) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
993 m += 12;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
994 y--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
995 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
996
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
997 t = 86400 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
998 (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
999
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1000 t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1001
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1002 return t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1003 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1004
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1005 /* Syntax:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1006 * - If not a duration:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1007 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1008 * Time is localtime unless Z is suffixed to the end. In this case GMT
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1009 * Return the date in micro seconds since 1970
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1010 * - If duration:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1011 * HH[:MM[:SS[.m...]]]
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1012 * S+[.m...]
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1013 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1014 int64_t parse_date(const char *datestr, int duration)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1015 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1016 const char *p;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1017 int64_t t;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1018 struct tm dt;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1019 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1020 static const char *date_fmt[] = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1021 "%Y-%m-%d",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1022 "%Y%m%d",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1023 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1024 static const char *time_fmt[] = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1025 "%H:%M:%S",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1026 "%H%M%S",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1027 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1028 const char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1029 int is_utc, len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1030 char lastch;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1031 time_t now = time(0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1032
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1033 len = strlen(datestr);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1034 if (len > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1035 lastch = datestr[len - 1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1036 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1037 lastch = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1038 is_utc = (lastch == 'z' || lastch == 'Z');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1039
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1040 memset(&dt, 0, sizeof(dt));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1041
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1042 p = datestr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1043 q = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1044 if (!duration) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1045 for (i = 0; i < sizeof(date_fmt) / sizeof(date_fmt[0]); i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1046 q = strptime(p, date_fmt[i], &dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1047 if (q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1048 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1049 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1050 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1051
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1052 if (!q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1053 if (is_utc) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1054 dt = *gmtime(&now);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1055 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1056 dt = *localtime(&now);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1057 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1058 dt.tm_hour = dt.tm_min = dt.tm_sec = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1059 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1060 p = q;
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 if (*p == 'T' || *p == 't' || *p == ' ')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1064 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1065
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1066 for (i = 0; i < sizeof(time_fmt) / sizeof(time_fmt[0]); i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1067 q = strptime(p, time_fmt[i], &dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1068 if (q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1069 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1070 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1071 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1072 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1073 q = strptime(p, time_fmt[0], &dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1074 if (!q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1075 dt.tm_sec = strtol(p, (char **)&q, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1076 dt.tm_min = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1077 dt.tm_hour = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1078 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1079 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1080
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1081 /* Now we have all the fields that we can get */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1082 if (!q) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1083 if (duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1084 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1085 else
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1086 return now * int64_t_C(1000000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1087 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1088
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1089 if (duration) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1090 t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1091 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1092 dt.tm_isdst = -1; /* unknown */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1093 if (is_utc) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1094 t = mktimegm(&dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1095 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1096 t = mktime(&dt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1097 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1098 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1099
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1100 t *= 1000000;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1101
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1102 if (*q == '.') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1103 int val, n;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1104 q++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1105 for (val = 0, n = 100000; n >= 1; n /= 10, q++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1106 if (!isdigit(*q))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1107 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1108 val += n * (*q - '0');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1109 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1110 t += val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1111 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1112 return t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1113 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1114
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1115 /* syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. Return
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1116 1 if found */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1117 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1118 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1119 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1120 char tag[128], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1121
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1122 p = info;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1123 if (*p == '?')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1124 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1125 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1126 q = tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1127 while (*p != '\0' && *p != '=' && *p != '&') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1128 if ((q - tag) < sizeof(tag) - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1129 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1130 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1131 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1132 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1133 q = arg;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1134 if (*p == '=') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1135 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1136 while (*p != '&' && *p != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1137 if ((q - arg) < arg_size - 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1138 if (*p == '+')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1139 *q++ = ' ';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1140 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1141 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1142 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1143 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1144 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1145 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1146 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1147 if (!strcmp(tag, tag1))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1148 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1149 if (*p != '&')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1150 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1151 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1152 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1153 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1154 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1155
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1156 /* Return in 'buf' the path with '%d' replaced by number. Also handles
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1157 the '%0nd' format where 'n' is the total number of digits and
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1158 '%%'. Return 0 if OK, and -1 if format error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1159 int get_frame_filename(char *buf, int buf_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1160 const char *path, int number)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1161 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1162 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1163 char *q, buf1[20];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1164 int nd, len, c, percentd_found;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1165
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1166 q = buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1167 p = path;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1168 percentd_found = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1169 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1170 c = *p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1171 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1172 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1173 if (c == '%') {
9
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1174 do {
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1175 nd = 0;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1176 while (isdigit(*p)) {
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1177 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
1178 }
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1179 c = *p++;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1180 if (c == '*' && nd > 0) {
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1181 // 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
1182 number = number % nd;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1183 c = *p++;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1184 nd = 0;
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1185 }
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1186 } while (isdigit(c));
97e61383cb81 * Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents: 7
diff changeset
1187
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1188 switch(c) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1189 case '%':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1190 goto addchar;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1191 case 'd':
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1192 if (percentd_found)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1193 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1194 percentd_found = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1195 snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1196 len = strlen(buf1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1197 if ((q - buf + len) > buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1198 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1199 memcpy(q, buf1, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1200 q += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1201 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1202 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1203 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1204 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1205 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1206 addchar:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1207 if ((q - buf) < buf_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1208 *q++ = c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1209 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1210 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1211 if (!percentd_found)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1212 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1213 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1214 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1215 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1216 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1217 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1218 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1219
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1220 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1221 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1222 * Print on stdout a nice hexa dump of a buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1223 * @param buf buffer
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1224 * @param size buffer size
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1225 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1226 void av_hex_dump(uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1227 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1228 int len, i, j, c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1229
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1230 for(i=0;i<size;i+=16) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1231 len = size - i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1232 if (len > 16)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1233 len = 16;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1234 printf("%08x ", i);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1235 for(j=0;j<16;j++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1236 if (j < len)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1237 printf(" %02x", buf[i+j]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1238 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1239 printf(" ");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1240 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1241 printf(" ");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1242 for(j=0;j<len;j++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1243 c = buf[i+j];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1244 if (c < ' ' || c > '~')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1245 c = '.';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1246 printf("%c", c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1247 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1248 printf("\n");
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 void url_split(char *proto, int proto_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1253 char *hostname, int hostname_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1254 int *port_ptr,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1255 char *path, int path_size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1256 const char *url)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1257 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1258 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1259 char *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1260 int port;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1261
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1262 port = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1263
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1264 p = url;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1265 q = proto;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1266 while (*p != ':' && *p != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1267 if ((q - proto) < proto_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1268 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1269 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1270 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1271 if (proto_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1272 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1273 if (*p == '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1274 if (proto_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1275 proto[0] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1276 if (hostname_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1277 hostname[0] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1278 p = url;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1279 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1280 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1281 if (*p == '/')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1282 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1283 if (*p == '/')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1284 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1285 q = hostname;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1286 while (*p != ':' && *p != '/' && *p != '?' && *p != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1287 if ((q - hostname) < hostname_size - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1288 *q++ = *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1289 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1290 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1291 if (hostname_size > 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1292 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1293 if (*p == ':') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1294 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1295 port = strtoul(p, (char **)&p, 10);
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 if (port_ptr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1299 *port_ptr = port;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1300 pstrcpy(path, path_size, p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1301 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1302
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1303 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1304 * Set the pts for a given stream
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1305 * @param s stream
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1306 * @param pts_wrap_bits number of bits effectively used by the pts
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1307 * (used for wrap control, 33 is the value for MPEG)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1308 * @param pts_num numerator to convert to seconds (MPEG: 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1309 * @param pts_den denominator to convert to seconds (MPEG: 90000)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1310 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1311 void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1312 int pts_num, int pts_den)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1313 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1314 s->pts_wrap_bits = pts_wrap_bits;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1315 s->pts_num = pts_num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1316 s->pts_den = pts_den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1317 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1318
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1319 /* fraction handling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1320
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1321 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1322 * f = val + (num / den) + 0.5. 'num' is normalized so that it is such
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1323 * as 0 <= num < den.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1324 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1325 * @param f fractional number
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1326 * @param val integer value
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1327 * @param num must be >= 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1328 * @param den must be >= 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1329 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1330 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
1331 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1332 num += (den >> 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1333 if (num >= den) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1334 val += num / den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1335 num = num % den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1336 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1337 f->val = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1338 f->num = num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1339 f->den = den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1340 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1341
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1342 /* set f to (val + 0.5) */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1343 void av_frac_set(AVFrac *f, int64_t val)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1344 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1345 f->val = val;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1346 f->num = f->den >> 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1347 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1348
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1349 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1350 * Fractionnal addition to f: f = f + (incr / f->den)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1351 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1352 * @param f fractional number
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1353 * @param incr increment, can be positive or negative
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1354 */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1355 void av_frac_add(AVFrac *f, int64_t incr)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1356 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 64
diff changeset
1357 int64_t num, den;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1358
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1359 num = f->num + incr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1360 den = f->den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1361 if (num < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1362 f->val += num / den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1363 num = num % den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1364 if (num < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1365 num += den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1366 f->val--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1367 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1368 } else if (num >= den) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1369 f->val += num / den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1370 num = num % den;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1371 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1372 f->num = num;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1373 }
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1374
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1375 /**
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1376 * register a new image format
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1377 * @param img_fmt Image format descriptor
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1378 */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1379 void av_register_image_format(AVImageFormat *img_fmt)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1380 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1381 AVImageFormat **p;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1382
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1383 p = &first_image_format;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1384 while (*p != NULL) p = &(*p)->next;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1385 *p = img_fmt;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1386 img_fmt->next = NULL;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1387 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1388
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1389 /* guess image format */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1390 AVImageFormat *av_probe_image_format(AVProbeData *pd)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1391 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1392 AVImageFormat *fmt1, *fmt;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1393 int score, score_max;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1394
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1395 fmt = NULL;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1396 score_max = 0;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1397 for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1398 if (fmt1->img_probe) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1399 score = fmt1->img_probe(pd);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1400 if (score > score_max) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1401 score_max = score;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1402 fmt = fmt1;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1403 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1404 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1405 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1406 return fmt;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1407 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1408
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1409 AVImageFormat *guess_image_format(const char *filename)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1410 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1411 AVImageFormat *fmt1;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1412
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1413 for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1414 if (fmt1->extensions && match_ext(filename, fmt1->extensions))
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1415 return fmt1;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1416 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1417 return NULL;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1418 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1419
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1420 /**
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1421 * Read an image from a stream.
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1422 * @param gb byte stream containing the image
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1423 * @param fmt image format, NULL if probing is required
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1424 */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1425 int av_read_image(ByteIOContext *pb, const char *filename,
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1426 AVImageFormat *fmt,
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1427 int (*alloc_cb)(void *, AVImageInfo *info), void *opaque)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1428 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1429 char buf[PROBE_BUF_SIZE];
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1430 AVProbeData probe_data, *pd = &probe_data;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1431 offset_t pos;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1432 int ret;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1433
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1434 if (!fmt) {
64
b0e0eb595e29 * static,const,compiler warning cleanup
kabi
parents: 53
diff changeset
1435 pd->filename = filename;
20
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1436 pd->buf = buf;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1437 pos = url_ftell(pb);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1438 pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1439 url_fseek(pb, pos, SEEK_SET);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1440 fmt = av_probe_image_format(pd);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1441 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1442 if (!fmt)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1443 return AVERROR_NOFMT;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1444 ret = fmt->img_read(pb, alloc_cb, opaque);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1445 return ret;
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1446 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1447
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1448 /**
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1449 * Write an image to a stream.
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1450 * @param pb byte stream for the image output
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1451 * @param fmt image format
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1452 * @param img image data and informations
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1453 */
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1454 int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img)
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1455 {
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1456 return fmt->img_write(pb, img);
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1457 }
3d52de18ecc3 added still image support
bellard
parents: 11
diff changeset
1458