Newer
Older
/* HACK/FIXME, we skip the initial 0-size packets as they are most likely equal to the encoder delay,
but it would be better if we had the real timestamps from the encoder */
if (frame_size >= 0 && (pkt->size || st->pts.num!=st->pts.den>>1 || st->pts.val)) {
av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
Fabrice Bellard
committed
}
break;
case CODEC_TYPE_VIDEO:
av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec.frame_rate_base);
break;
default:
break;
}
}
static void truncate_ts(AVStream *st, AVPacket *pkt){
int64_t pts_mask = (2LL << (st->pts_wrap_bits-1)) - 1;
// if(pkt->dts < 0)
// pkt->dts= 0; //this happens for low_delay=0 and b frames, FIXME, needs further invstigation about what we should do here
pkt->pts &= pts_mask;
pkt->dts &= pts_mask;
}
/**
* Write a packet to an output media file. The packet shall contain
* one audio or video frame.
*
* @param s media file handle
* @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
* @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
*/
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
{
compute_pkt_fields2(s->streams[pkt->stream_index], pkt);
truncate_ts(s->streams[pkt->stream_index], pkt);
ret= s->oformat->write_packet(s, pkt);
if(!ret)
ret= url_ferror(&s->pb);
return ret;
Michael Niedermayer
committed
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
/**
* interleave_packet implementation which will interleave per DTS.
*/
static int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){
AVPacketList *pktl, **next_point, *this_pktl;
int stream_count=0;
int streams[MAX_STREAMS];
if(pkt){
AVStream *st= s->streams[ pkt->stream_index];
assert(pkt->destruct != av_destruct_packet); //FIXME
this_pktl = av_mallocz(sizeof(AVPacketList));
this_pktl->pkt= *pkt;
av_dup_packet(&this_pktl->pkt);
next_point = &s->packet_buffer;
while(*next_point){
AVStream *st2= s->streams[ (*next_point)->pkt.stream_index];
int64_t left= st2->time_base.num * (int64_t)st ->time_base.den;
int64_t right= st ->time_base.num * (int64_t)st2->time_base.den;
if((*next_point)->pkt.dts * left > pkt->dts * right) //FIXME this can overflow
break;
next_point= &(*next_point)->next;
}
this_pktl->next= *next_point;
*next_point= this_pktl;
}
memset(streams, 0, sizeof(streams));
pktl= s->packet_buffer;
while(pktl){
//av_log(s, AV_LOG_DEBUG, "show st:%d dts:%lld\n", pktl->pkt.stream_index, pktl->pkt.dts);
if(streams[ pktl->pkt.stream_index ] == 0)
stream_count++;
streams[ pktl->pkt.stream_index ]++;
pktl= pktl->next;
}
if(s->nb_streams == stream_count || (flush && stream_count)){
pktl= s->packet_buffer;
*out= pktl->pkt;
s->packet_buffer= pktl->next;
av_freep(&pktl);
return 1;
}else{
av_init_packet(out);
return 0;
}
}
/**
* Interleaves a AVPacket correctly so it can be muxed.
* @param out the interleaved packet will be output here
* @param in the input packet
* @param flush 1 if no further packets are available as input and all
* remaining packets should be output
* @return 1 if a packet was output, 0 if no packet could be output,
* < 0 if an error occured
*/
static int av_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush){
if(s->oformat->interleave_packet)
return s->oformat->interleave_packet(s, out, in, flush);
else
return av_interleave_packet_per_dts(s, out, in, flush);
}
/**
* Writes a packet to an output media file ensuring correct interleaving.
* The packet shall contain one audio or video frame.
* If the packets are already correctly interleaved the application should
* call av_write_frame() instead as its slightly faster, its also important
Michael Niedermayer
committed
* to keep in mind that completly non interleaved input will need huge amounts
* of memory to interleave with this, so its prefereable to interleave at the
* demuxer level
*
* @param s media file handle
* @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
* @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
*/
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){
AVStream *st= s->streams[ pkt->stream_index];
compute_pkt_fields2(st, pkt);
//FIXME/XXX/HACK drop zero sized packets
if(st->codec.codec_type == CODEC_TYPE_AUDIO && pkt->size==0)
return 0;
Michael Niedermayer
committed
if(pkt->dts == AV_NOPTS_VALUE)
return -1;
Michael Niedermayer
committed
for(;;){
AVPacket opkt;
int ret= av_interleave_packet(s, &opkt, pkt, 0);
if(ret<=0) //FIXME cleanup needed for ret<0 ?
return ret;
Michael Niedermayer
committed
truncate_ts(s->streams[opkt.stream_index], &opkt);
ret= s->oformat->write_packet(s, &opkt);
av_free_packet(&opkt);
pkt= NULL;
if(ret<0)
return ret;
if(url_ferror(&s->pb))
return url_ferror(&s->pb);
Fabrice Bellard
committed
}
/**
* write the stream trailer to an output media file and and free the
* file private data.
*
* @param s media file handle
* @return 0 if OK. AVERROR_xxx if error. */
int av_write_trailer(AVFormatContext *s)
{
int ret, i;
Michael Niedermayer
committed
for(;;){
AVPacket pkt;
ret= av_interleave_packet(s, &pkt, NULL, 1);
if(ret<0) //FIXME cleanup needed for ret<0 ?
goto fail;
Michael Niedermayer
committed
if(!ret)
break;
Michael Niedermayer
committed
truncate_ts(s->streams[pkt.stream_index], &pkt);
ret= s->oformat->write_packet(s, &pkt);
av_free_packet(&pkt);
goto fail;
Fabrice Bellard
committed
ret = s->oformat->write_trailer(s);
for(i=0;i<s->nb_streams;i++)
av_freep(&s->streams[i]->priv_data);
Fabrice Bellard
committed
av_freep(&s->priv_data);
return ret;
}
/* "user interface" functions */
void dump_format(AVFormatContext *ic,
int index,
const char *url,
int is_output)
{
Fabrice Bellard
committed
int i, flags;
av_log(NULL, AV_LOG_DEBUG, "%s #%d, %s, %s '%s':\n",
Fabrice Bellard
committed
index,
is_output ? ic->oformat->name : ic->iformat->name,
Fabrice Bellard
committed
if (!is_output) {
Fabrice Bellard
committed
if (ic->duration != AV_NOPTS_VALUE) {
int hours, mins, secs, us;
secs = ic->duration / AV_TIME_BASE;
us = ic->duration % AV_TIME_BASE;
mins = secs / 60;
secs %= 60;
hours = mins / 60;
mins %= 60;
av_log(NULL, AV_LOG_DEBUG, "%02d:%02d:%02d.%01d", hours, mins, secs,
Fabrice Bellard
committed
(10 * us) / AV_TIME_BASE);
} else {
Fabrice Bellard
committed
}
Wolfram Gloger
committed
if (ic->start_time != AV_NOPTS_VALUE) {
int secs, us;
av_log(NULL, AV_LOG_DEBUG, ", start: ");
secs = ic->start_time / AV_TIME_BASE;
us = ic->start_time % AV_TIME_BASE;
av_log(NULL, AV_LOG_DEBUG, "%d.%06d",
secs, (int)av_rescale(us, 1000000, AV_TIME_BASE));
}
Fabrice Bellard
committed
if (ic->bit_rate) {
av_log(NULL, AV_LOG_DEBUG,"%d kb/s", ic->bit_rate / 1000);
Fabrice Bellard
committed
} else {
Fabrice Bellard
committed
}
Fabrice Bellard
committed
}
for(i=0;i<ic->nb_streams;i++) {
AVStream *st = ic->streams[i];
avcodec_string(buf, sizeof(buf), &st->codec, is_output);
av_log(NULL, AV_LOG_DEBUG, " Stream #%d.%d", index, i);
Fabrice Bellard
committed
/* the pid is an important information, so we display it */
/* XXX: add a generic system */
if (is_output)
flags = ic->oformat->flags;
else
flags = ic->iformat->flags;
if (flags & AVFMT_SHOW_IDS) {
Fabrice Bellard
committed
}
int frame_rate, frame_rate_base;
} AbvEntry;
static AbvEntry frame_abvs[] = {
{ "ntsc", 720, 480, 30000, 1001 },
{ "pal", 720, 576, 25, 1 },
{ "qntsc", 352, 240, 30000, 1001 }, /* VCD compliant ntsc */
{ "qpal", 352, 288, 25, 1 }, /* VCD compliant pal */
{ "sntsc", 640, 480, 30000, 1001 }, /* square pixel ntsc */
{ "spal", 768, 576, 25, 1 }, /* square pixel pal */
{ "film", 352, 240, 24, 1 },
{ "ntsc-film", 352, 240, 24000, 1001 },
{ "sqcif", 128, 96, 0, 0 },
{ "qcif", 176, 144, 0, 0 },
{ "cif", 352, 288, 0, 0 },
{ "4cif", 704, 576, 0, 0 },
int parse_image_size(int *width_ptr, int *height_ptr, const char *str)
{
int i;
int n = sizeof(frame_abvs) / sizeof(AbvEntry);
const char *p;
int frame_width = 0, frame_height = 0;
for(i=0;i<n;i++) {
if (!strcmp(frame_abvs[i].abv, str)) {
frame_width = frame_abvs[i].width;
frame_height = frame_abvs[i].height;
break;
}
}
if (i == n) {
p = str;
frame_width = strtol(p, (char **)&p, 10);
if (*p)
p++;
frame_height = strtol(p, (char **)&p, 10);
}
if (frame_width <= 0 || frame_height <= 0)
return -1;
*width_ptr = frame_width;
*height_ptr = frame_height;
return 0;
}
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg)
{
int i;
char* cp;
/* First, we check our abbreviation table */
for (i = 0; i < sizeof(frame_abvs)/sizeof(*frame_abvs); ++i)
if (!strcmp(frame_abvs[i].abv, arg)) {
*frame_rate = frame_abvs[i].frame_rate;
*frame_rate_base = frame_abvs[i].frame_rate_base;
return 0;
}
/* Then, we try to parse it as fraction */
cp = strchr(arg, '/');
if (cp) {
char* cpp;
*frame_rate = strtol(arg, &cpp, 10);
if (cpp != arg || cpp == cp)
*frame_rate_base = strtol(cp+1, &cpp, 10);
else
*frame_rate = 0;
}
else {
/* Finally we give up and parse it as double */
*frame_rate_base = DEFAULT_FRAME_RATE_BASE; //FIXME use av_d2q()
*frame_rate = (int)(strtod(arg, 0) * (*frame_rate_base) + 0.5);
}
if (!*frame_rate || !*frame_rate_base)
return -1;
else
return 0;
}
/* Syntax:
* - If not a duration:
* [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
Philip Gladstone
committed
* Time is localtime unless Z is suffixed to the end. In this case GMT
* Return the date in micro seconds since 1970
* - If duration:
* HH[:MM[:SS[.m...]]]
* S+[.m...]
*/
int64_t parse_date(const char *datestr, int duration)
Philip Gladstone
committed
struct tm dt;
Philip Gladstone
committed
int i;
static const char *date_fmt[] = {
"%Y-%m-%d",
"%Y%m%d",
};
static const char *time_fmt[] = {
"%H:%M:%S",
"%H%M%S",
};
const char *q;
Philip Gladstone
committed
char lastch;
#undef time
Philip Gladstone
committed
time_t now = time(0);
len = strlen(datestr);
if (len > 0)
lastch = datestr[len - 1];
else
lastch = '\0';
Philip Gladstone
committed
is_utc = (lastch == 'z' || lastch == 'Z');
Philip Gladstone
committed
memset(&dt, 0, sizeof(dt));
Philip Gladstone
committed
for (i = 0; i < sizeof(date_fmt) / sizeof(date_fmt[0]); i++) {
Fabrice Bellard
committed
q = small_strptime(p, date_fmt[i], &dt);
Philip Gladstone
committed
if (q) {
break;
}
}
if (!q) {
if (is_utc) {
dt = *gmtime(&now);
} else {
dt = *localtime(&now);
}
dt.tm_hour = dt.tm_min = dt.tm_sec = 0;
Philip Gladstone
committed
p = q;
Philip Gladstone
committed
if (*p == 'T' || *p == 't' || *p == ' ')
p++;
for (i = 0; i < sizeof(time_fmt) / sizeof(time_fmt[0]); i++) {
Fabrice Bellard
committed
q = small_strptime(p, time_fmt[i], &dt);
if (q) {
break;
}
}
} else {
if (p[0] == '-') {
negative = 1;
++p;
}
Fabrice Bellard
committed
q = small_strptime(p, time_fmt[0], &dt);
if (!q) {
dt.tm_sec = strtol(p, (char **)&q, 10);
dt.tm_min = 0;
dt.tm_hour = 0;
Philip Gladstone
committed
}
}
/* Now we have all the fields that we can get */
if (!q) {
if (duration)
return 0;
else
Philip Gladstone
committed
if (duration) {
Philip Gladstone
committed
t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
Philip Gladstone
committed
} else {
Philip Gladstone
committed
dt.tm_isdst = -1; /* unknown */
if (is_utc) {
t = mktimegm(&dt);
} else {
t = mktime(&dt);
}
Philip Gladstone
committed
Philip Gladstone
committed
t *= 1000000;
if (*q == '.') {
Philip Gladstone
committed
q++;
for (val = 0, n = 100000; n >= 1; n /= 10, q++) {
if (!isdigit(*q))
break;
val += n * (*q - '0');
Philip Gladstone
committed
/* syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. Return
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
1 if found */
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
{
const char *p;
char tag[128], *q;
p = info;
if (*p == '?')
p++;
for(;;) {
q = tag;
while (*p != '\0' && *p != '=' && *p != '&') {
if ((q - tag) < sizeof(tag) - 1)
*q++ = *p;
p++;
}
*q = '\0';
q = arg;
if (*p == '=') {
p++;
while (*p != '&' && *p != '\0') {
Philip Gladstone
committed
if ((q - arg) < arg_size - 1) {
if (*p == '+')
*q++ = ' ';
else
*q++ = *p;
}
p++;
}
*q = '\0';
}
if (!strcmp(tag, tag1))
return 1;
if (*p != '&')
break;
/* Return in 'buf' the path with '%d' replaced by number. Also handles
the '%0nd' format where 'n' is the total number of digits and
'%%'. Return 0 if OK, and -1 if format error */
int get_frame_filename(char *buf, int buf_size,
const char *path, int number)
{
const char *p;
Panagiotis Issaris
committed
char *q, buf1[20], c;
int nd, len, percentd_found;
q = buf;
p = path;
percentd_found = 0;
for(;;) {
c = *p++;
if (c == '\0')
break;
if (c == '%') {
Philip Gladstone
committed
do {
nd = 0;
while (isdigit(*p)) {
nd = nd * 10 + *p++ - '0';
}
c = *p++;
} while (isdigit(c));
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
switch(c) {
case '%':
goto addchar;
case 'd':
if (percentd_found)
goto fail;
percentd_found = 1;
snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
len = strlen(buf1);
if ((q - buf + len) > buf_size - 1)
goto fail;
memcpy(q, buf1, len);
q += len;
break;
default:
goto fail;
}
} else {
addchar:
if ((q - buf) < buf_size - 1)
*q++ = c;
}
}
if (!percentd_found)
goto fail;
*q = '\0';
return 0;
fail:
*q = '\0';
return -1;
}
Fabrice Bellard
committed
/**
* Print nice hexa dump of a buffer
* @param f stream for output
Fabrice Bellard
committed
* @param buf buffer
* @param size buffer size
*/
void av_hex_dump(FILE *f, uint8_t *buf, int size)
Fabrice Bellard
committed
{
int len, i, j, c;
for(i=0;i<size;i+=16) {
len = size - i;
if (len > 16)
len = 16;
fprintf(f, "%08x ", i);
Fabrice Bellard
committed
for(j=0;j<16;j++) {
if (j < len)
fprintf(f, " %02x", buf[i+j]);
Fabrice Bellard
committed
else
Fabrice Bellard
committed
}
Fabrice Bellard
committed
for(j=0;j<len;j++) {
c = buf[i+j];
if (c < ' ' || c > '~')
c = '.';
fprintf(f, "%c", c);
Fabrice Bellard
committed
}
fprintf(f, "\n");
Fabrice Bellard
committed
}
}
/**
* Print on 'f' a nice dump of a packet
* @param f stream for output
* @param pkt packet to dump
* @param dump_payload true if the payload must be displayed too
*/
void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload)
{
fprintf(f, "stream #%d:\n", pkt->stream_index);
fprintf(f, " keyframe=%d\n", ((pkt->flags & PKT_FLAG_KEY) != 0));
fprintf(f, " duration=%0.3f\n", (double)pkt->duration / AV_TIME_BASE);
/* DTS is _always_ valid after av_read_frame() */
fprintf(f, " dts=");
if (pkt->dts == AV_NOPTS_VALUE)
fprintf(f, "N/A");
else
fprintf(f, "%0.3f", (double)pkt->dts / AV_TIME_BASE);
/* PTS may be not known if B frames are present */
fprintf(f, " pts=");
if (pkt->pts == AV_NOPTS_VALUE)
fprintf(f, "N/A");
else
fprintf(f, "%0.3f", (double)pkt->pts / AV_TIME_BASE);
fprintf(f, "\n");
fprintf(f, " size=%d\n", pkt->size);
if (dump_payload)
av_hex_dump(f, pkt->data, pkt->size);
}
Petr Doubek
committed
char *authorization, int authorization_size,
char *hostname, int hostname_size,
int *port_ptr,
char *path, int path_size,
const char *url)
{
const char *p;
char *q;
int port;
port = -1;
p = url;
q = proto;
while (*p != ':' && *p != '\0') {
if ((q - proto) < proto_size - 1)
*q++ = *p;
p++;
}
if (proto_size > 0)
*q = '\0';
Petr Doubek
committed
if (authorization_size > 0)
authorization[0] = '\0';
if (*p == '\0') {
if (proto_size > 0)
proto[0] = '\0';
if (hostname_size > 0)
hostname[0] = '\0';
p = url;
} else {
Petr Doubek
committed
char *at,*slash; // PETR: position of '@' character and '/' character
p++;
if (*p == '/')
p++;
if (*p == '/')
p++;
Petr Doubek
committed
at = strchr(p,'@'); // PETR: get the position of '@'
slash = strchr(p,'/'); // PETR: get position of '/' - end of hostname
if (at && slash && at > slash) at = NULL; // PETR: not interested in '@' behind '/'
q = at ? authorization : hostname; // PETR: if '@' exists starting with auth.
while ((at || *p != ':') && *p != '/' && *p != '?' && *p != '\0') { // PETR:
if (*p == '@') { // PETR: passed '@'
if (authorization_size > 0)
*q = '\0';
q = hostname;
at = NULL;
} else if (!at) { // PETR: hostname
if ((q - hostname) < hostname_size - 1)
*q++ = *p;
} else {
if ((q - authorization) < authorization_size - 1)
Petr Doubek
committed
}
p++;
}
if (hostname_size > 0)
*q = '\0';
if (*p == ':') {
p++;
port = strtoul(p, (char **)&p, 10);
}
}
if (port_ptr)
*port_ptr = port;
pstrcpy(path, path_size, p);
}
/**
* Set the pts for a given stream
* @param s stream
* @param pts_wrap_bits number of bits effectively used by the pts
* (used for wrap control, 33 is the value for MPEG)
* @param pts_num numerator to convert to seconds (MPEG: 1)
* @param pts_den denominator to convert to seconds (MPEG: 90000)
*/
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
int pts_num, int pts_den)
{
s->pts_wrap_bits = pts_wrap_bits;
s->time_base.num = pts_num;
s->time_base.den = pts_den;
}
/* fraction handling */
/**
* f = val + (num / den) + 0.5. 'num' is normalized so that it is such
* as 0 <= num < den.
*
* @param f fractional number
* @param val integer value
* @param num must be >= 0
* @param den must be >= 1
*/
void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
{
num += (den >> 1);
if (num >= den) {
val += num / den;
num = num % den;
}
f->val = val;
f->num = num;
f->den = den;
}
/* set f to (val + 0.5) */
void av_frac_set(AVFrac *f, int64_t val)
{
f->val = val;
f->num = f->den >> 1;
}
/**
* Fractionnal addition to f: f = f + (incr / f->den)
*
* @param f fractional number
* @param incr increment, can be positive or negative
*/
void av_frac_add(AVFrac *f, int64_t incr)
num = f->num + incr;
den = f->den;
if (num < 0) {
f->val += num / den;
num = num % den;
if (num < 0) {
num += den;
f->val--;
}
} else if (num >= den) {
f->val += num / den;
num = num % den;
}
f->num = num;
}
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
/**
* register a new image format
* @param img_fmt Image format descriptor
*/
void av_register_image_format(AVImageFormat *img_fmt)
{
AVImageFormat **p;
p = &first_image_format;
while (*p != NULL) p = &(*p)->next;
*p = img_fmt;
img_fmt->next = NULL;
}
/* guess image format */
AVImageFormat *av_probe_image_format(AVProbeData *pd)
{
AVImageFormat *fmt1, *fmt;
int score, score_max;
fmt = NULL;
score_max = 0;
for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {
if (fmt1->img_probe) {
score = fmt1->img_probe(pd);
if (score > score_max) {
score_max = score;
fmt = fmt1;
}
}
}
return fmt;
}
AVImageFormat *guess_image_format(const char *filename)
{
AVImageFormat *fmt1;
for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {
if (fmt1->extensions && match_ext(filename, fmt1->extensions))
return fmt1;
}
return NULL;
}
/**
* Read an image from a stream.
* @param gb byte stream containing the image
* @param fmt image format, NULL if probing is required
*/
int av_read_image(ByteIOContext *pb, const char *filename,
AVImageFormat *fmt,
int (*alloc_cb)(void *, AVImageInfo *info), void *opaque)
{
char buf[PROBE_BUF_SIZE];
AVProbeData probe_data, *pd = &probe_data;
offset_t pos;
int ret;
if (!fmt) {
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
pd->buf = buf;
pos = url_ftell(pb);
pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
url_fseek(pb, pos, SEEK_SET);
fmt = av_probe_image_format(pd);
}
if (!fmt)
return AVERROR_NOFMT;
ret = fmt->img_read(pb, alloc_cb, opaque);
return ret;
}
/**
* Write an image to a stream.
* @param pb byte stream for the image output
* @param fmt image format
* @param img image data and informations
*/
int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img)
{
return fmt->img_write(pb, img);
}