Merge commit '10aa44aa675e05067845e3e55fac37642cbbdae4'

* commit '10aa44aa675e05067845e3e55fac37642cbbdae4':
  avidec: K&R formatting cosmetics

Conflicts:
	libavformat/avidec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer
2013-07-28 13:06:38 +02:00
+213 -115
View File
@@ -19,36 +19,37 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/bswap.h"
#include "libavutil/opt.h"
#include "libavutil/dict.h"
#include "libavutil/avstring.h"
#include "libavutil/avassert.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "avformat.h"
#include "internal.h"
#include "avi.h"
#include "dv.h"
#include "internal.h"
#include "riff.h"
typedef struct AVIStream {
int64_t frame_offset; /* current frame (video) or byte (audio) counter
(used to compute the pts) */
* (used to compute the pts) */
int remaining;
int packet_size;
uint32_t scale;
uint32_t rate;
int sample_size; /* size of one sample (or packet) (in the rate/scale sense) in bytes */
int sample_size; /* size of one sample (or packet)
* (in the rate/scale sense) in bytes */
int64_t cum_len; /* temporary storage (used during seek) */
int prefix; ///< normally 'd'<<8 + 'c' or 'w'<<8 + 'b'
int prefix; /* normally 'd'<<8 + 'c' or 'w'<<8 + 'b' */
int prefix_count;
uint32_t pal[256];
int has_pal;
int dshow_block_align; ///< block align variable used to emulate bugs in the MS dshow demuxer
int dshow_block_align; /* block align variable used to emulate bugs in
* the MS dshow demuxer */
AVFormatContext *sub_ctx;
AVPacket sub_pkt;
@@ -116,12 +117,13 @@ static int guess_ni_flag(AVFormatContext *s);
(tag >> 24) & 0xff, \
size)
static inline int get_duration(AVIStream *ast, int len){
if(ast->sample_size){
static inline int get_duration(AVIStream *ast, int len)
{
if (ast->sample_size)
return len;
}else if (ast->dshow_block_align){
else if (ast->dshow_block_align)
return (len + ast->dshow_block_align - 1) / ast->dshow_block_align;
}else
else
return 1;
}
@@ -144,12 +146,14 @@ static int get_riff(AVFormatContext *s, AVIOContext *pb)
return AVERROR_INVALIDDATA;
if (header[7] == 0x19)
av_log(s, AV_LOG_INFO, "This file has been generated by a totally broken muxer.\n");
av_log(s, AV_LOG_INFO,
"This file has been generated by a totally broken muxer.\n");
return 0;
}
static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
static int read_braindead_odml_indx(AVFormatContext *s, int frame_num)
{
AVIContext *avi = s->priv_data;
AVIOContext *pb = s->pb;
int longs_pre_entry = avio_rl16(pb);
@@ -158,15 +162,22 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
int entries_in_use = avio_rl32(pb);
int chunk_id = avio_rl32(pb);
int64_t base = avio_rl64(pb);
int stream_id= 10*((chunk_id&0xFF) - '0') + (((chunk_id>>8)&0xFF) - '0');
int stream_id = ((chunk_id & 0xFF) - '0') * 10 +
((chunk_id >> 8 & 0xFF) - '0');
AVStream *st;
AVIStream *ast;
int i;
int64_t last_pos = -1;
int64_t filesize = avi->fsize;
av_dlog(s, "longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%16"PRIX64"\n",
longs_pre_entry,index_type, entries_in_use, chunk_id, base);
av_dlog(s,
"longs_pre_entry:%d index_type:%d entries_in_use:%d "
"chunk_id:%X base:%16"PRIX64"\n",
longs_pre_entry,
index_type,
entries_in_use,
chunk_id,
base);
if (stream_id >= s->nb_streams || stream_id < 0)
return AVERROR_INVALIDDATA;
@@ -185,7 +196,9 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
if (filesize > 0 && base >= filesize) {
av_log(s, AV_LOG_ERROR, "ODML index invalid\n");
if(base>>32 == (base & 0xFFFFFFFF) && (base & 0xFFFFFFFF) < filesize && filesize <= 0xFFFFFFFF)
if (base >> 32 == (base & 0xFFFFFFFF) &&
(base & 0xFFFFFFFF) < filesize &&
filesize <= 0xFFFFFFFF)
base &= 0xFFFFFFFF;
else
return AVERROR_INVALIDDATA;
@@ -207,7 +220,8 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
if (last_pos == pos || pos == base - 8)
avi->non_interleaved = 1;
if (last_pos != pos && (len || !ast->sample_size))
av_add_index_entry(st, pos, ast->cum_len, len, 0, key ? AVINDEX_KEYFRAME : 0);
av_add_index_entry(st, pos, ast->cum_len, len, 0,
key ? AVINDEX_KEYFRAME : 0);
ast->cum_len += get_duration(ast, len);
last_pos = pos;
@@ -246,7 +260,8 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
return 0;
}
static void clean_index(AVFormatContext *s){
static void clean_index(AVFormatContext *s)
{
int i;
int64_t j;
@@ -260,22 +275,25 @@ static void clean_index(AVFormatContext *s){
if (n != 1 || ast->sample_size == 0)
continue;
while(max < 1024) max+=max;
while (max < 1024)
max += max;
pos = st->index_entries[0].pos;
size = st->index_entries[0].size;
ts = st->index_entries[0].timestamp;
for(j=0; j<size; j+=max){
av_add_index_entry(st, pos+j, ts+j, FFMIN(max, size-j), 0, AVINDEX_KEYFRAME);
}
for (j = 0; j < size; j += max)
av_add_index_entry(st, pos + j, ts + j, FFMIN(max, size - j), 0,
AVINDEX_KEYFRAME);
}
}
static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag, uint32_t size)
static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag,
uint32_t size)
{
AVIOContext *pb = s->pb;
char key[5] = {0}, *value;
char key[5] = { 0 };
char *value;
size += (size & 1);
@@ -321,7 +339,8 @@ static void avi_read_nikon(AVFormatContext *s, uint64_t end)
uint32_t tag = avio_rl32(s->pb);
uint32_t size = avio_rl32(s->pb);
switch (tag) {
case MKTAG('n', 'c', 't', 'g'): { /* Nikon Tags */
case MKTAG('n', 'c', 't', 'g'): /* Nikon Tags */
{
uint64_t tag_end = avio_tell(s->pb) + size;
while (avio_tell(s->pb) < tag_end) {
uint16_t tag = avio_rl16(s->pb);
@@ -331,9 +350,14 @@ static void avi_read_nikon(AVFormatContext *s, uint64_t end)
size -= avio_read(s->pb, buffer,
FFMIN(size, sizeof(buffer) - 1));
switch (tag) {
case 0x03: name = "maker"; break;
case 0x04: name = "model"; break;
case 0x13: name = "creation_time";
case 0x03:
name = "maker";
break;
case 0x04:
name = "model";
break;
case 0x13:
name = "creation_time";
if (buffer[4] == ':' && buffer[7] == ':')
buffer[4] = buffer[7] = '-';
break;
@@ -401,18 +425,20 @@ static int avi_read_header(AVFormatContext *s)
if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
avi->movi_list = avio_tell(pb) - 4;
if(size) avi->movi_end = avi->movi_list + size + (size & 1);
else avi->movi_end = avi->fsize;
if (size)
avi->movi_end = avi->movi_list + size + (size & 1);
else
avi->movi_end = avi->fsize;
av_dlog(NULL, "movi end=%"PRIx64"\n", avi->movi_end);
goto end_of_header;
}
else if (tag1 == MKTAG('I', 'N', 'F', 'O'))
} else if (tag1 == MKTAG('I', 'N', 'F', 'O'))
ff_read_riff_info(s, size - 4);
else if (tag1 == MKTAG('n', 'c', 'd', 't'))
avi_read_nikon(s, list_end);
break;
case MKTAG('I', 'D', 'I', 'T'): {
case MKTAG('I', 'D', 'I', 'T'):
{
unsigned char date[64] = { 0 };
size += (size & 1);
size -= avio_read(pb, date, FFMIN(size, sizeof(date) - 1));
@@ -464,17 +490,17 @@ static int avi_read_header(AVFormatContext *s)
st->priv_data = ast;
}
if (amv_file_format)
tag1 = stream_index ? MKTAG('a','u','d','s') : MKTAG('v','i','d','s');
tag1 = stream_index ? MKTAG('a', 'u', 'd', 's')
: MKTAG('v', 'i', 'd', 's');
print_tag("strh", tag1, -1);
if(tag1 == MKTAG('i', 'a', 'v', 's') || tag1 == MKTAG('i', 'v', 'a', 's')){
if (tag1 == MKTAG('i', 'a', 'v', 's') ||
tag1 == MKTAG('i', 'v', 'a', 's')) {
int64_t dv_dur;
/*
* After some consideration -- I don't think we
* have to support anything but DV in type1 AVIs.
*/
/* After some consideration -- I don't think we
* have to support anything but DV in type1 AVIs. */
if (s->nb_streams != 1)
goto fail;
@@ -507,10 +533,8 @@ static int avi_read_header(AVFormatContext *s)
dv_dur *= AV_TIME_BASE;
s->duration = av_rescale(dv_dur, ast->scale, ast->rate);
}
/*
* else, leave duration alone; timing estimation in utils.c
* will make a guess based on bitrate.
*/
/* else, leave duration alone; timing estimation in utils.c
* will make a guess based on bitrate. */
stream_index = s->nb_streams - 1;
avio_skip(pb, size - 9 * 4);
@@ -527,7 +551,11 @@ static int avi_read_header(AVFormatContext *s)
ast->scale = avio_rl32(pb);
ast->rate = avio_rl32(pb);
if (!(ast->scale && ast->rate)) {
av_log(s, AV_LOG_WARNING, "scale/rate is %u/%u which is invalid. (This file has been generated by broken software.)\n", ast->scale, ast->rate);
av_log(s, AV_LOG_WARNING,
"scale/rate is %u/%u which is invalid. "
"(This file has been generated by broken software.)\n",
ast->scale,
ast->rate);
if (frame_period) {
ast->rate = 1000000;
ast->scale = frame_period;
@@ -605,7 +633,8 @@ static int avi_read_header(AVFormatContext *s)
}
tag1 = ff_get_bmp_header(pb, st, &esize);
if (tag1 == MKTAG('D', 'X', 'S', 'B') || tag1 == MKTAG('D','X','S','A')) {
if (tag1 == MKTAG('D', 'X', 'S', 'B') ||
tag1 == MKTAG('D', 'X', 'S', 'A')) {
st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
st->codec->codec_tag = tag1;
st->codec->codec_id = AV_CODEC_ID_XSUB;
@@ -613,28 +642,37 @@ static int avi_read_header(AVFormatContext *s)
}
if (size > 10 * 4 && size < (1 << 30) && size < avi->fsize) {
if(esize == size-1 && (esize&1)) st->codec->extradata_size= esize - 10*4;
else st->codec->extradata_size= size - 10*4;
st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
if (esize == size-1 && (esize&1)) {
st->codec->extradata_size = esize - 10 * 4;
} else
st->codec->extradata_size = size - 10 * 4;
st->codec->extradata = av_malloc(st->codec->extradata_size +
FF_INPUT_BUFFER_PADDING_SIZE);
if (!st->codec->extradata) {
st->codec->extradata_size = 0;
return AVERROR(ENOMEM);
}
avio_read(pb, st->codec->extradata, st->codec->extradata_size);
avio_read(pb,
st->codec->extradata,
st->codec->extradata_size);
}
if(st->codec->extradata_size & 1) //FIXME check if the encoder really did this correctly
// FIXME: check if the encoder really did this correctly
if (st->codec->extradata_size & 1)
avio_r8(pb);
/* Extract palette from extradata if bpp <= 8. */
/* This code assumes that extradata contains only palette. */
/* This is true for all paletted codecs implemented in FFmpeg. */
if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) {
/* Extract palette from extradata if bpp <= 8.
* This code assumes that extradata contains only palette.
* This is true for all paletted codecs implemented in
* FFmpeg. */
if (st->codec->extradata_size &&
(st->codec->bits_per_coded_sample <= 8)) {
int pal_size = (1 << st->codec->bits_per_coded_sample) << 2;
const uint8_t *pal_src;
pal_size = FFMIN(pal_size, st->codec->extradata_size);
pal_src = st->codec->extradata + st->codec->extradata_size - pal_size;
pal_src = st->codec->extradata +
st->codec->extradata_size - pal_size;
for (i = 0; i < pal_size / 4; i++)
ast->pal[i] = 0xFFU<<24 | AV_RL32(pal_src+4*i);
ast->has_pal = 1;
@@ -644,14 +682,22 @@ static int avi_read_header(AVFormatContext *s)
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_tag = tag1;
st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1);
st->need_parsing = AVSTREAM_PARSE_HEADERS; // This is needed to get the pict type which is necessary for generating correct pts.
st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags,
tag1);
/* This is needed to get the pict type which is necessary
* for generating correct pts. */
st->need_parsing = AVSTREAM_PARSE_HEADERS;
if(st->codec->codec_tag==0 && st->codec->height > 0 && st->codec->extradata_size < 1U<<30){
if (st->codec->codec_tag == 0 && st->codec->height > 0 &&
st->codec->extradata_size < 1U << 30) {
st->codec->extradata_size += 9;
st->codec->extradata= av_realloc_f(st->codec->extradata, 1, st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
st->codec->extradata = av_realloc_f(st->codec->extradata,
1,
st->codec->extradata_size +
FF_INPUT_BUFFER_PADDING_SIZE);
if (st->codec->extradata)
memcpy(st->codec->extradata + st->codec->extradata_size - 9, "BottomUp", 9);
memcpy(st->codec->extradata + st->codec->extradata_size - 9,
"BottomUp", 9);
}
st->codec->height = FFABS(st->codec->height);
@@ -662,11 +708,18 @@ static int avi_read_header(AVFormatContext *s)
if (ret < 0)
return ret;
ast->dshow_block_align = st->codec->block_align;
if(ast->sample_size && st->codec->block_align && ast->sample_size != st->codec->block_align){
av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, st->codec->block_align);
if (ast->sample_size && st->codec->block_align &&
ast->sample_size != st->codec->block_align) {
av_log(s,
AV_LOG_WARNING,
"sample size (%d) != block align (%d)\n",
ast->sample_size,
st->codec->block_align);
ast->sample_size = st->codec->block_align;
}
if (size&1) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
/* 2-aligned
* (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
if (size & 1)
avio_skip(pb, 1);
/* Force parsing as several audio frames can be in
* one packet and timestamps refer to packet start. */
@@ -674,7 +727,8 @@ static int avi_read_header(AVFormatContext *s)
/* ADTS header is in extradata, AAC without header must be
* stored as exact frames. Parser not needed and it will
* fail. */
if (st->codec->codec_id == AV_CODEC_ID_AAC && st->codec->extradata_size)
if (st->codec->codec_id == AV_CODEC_ID_AAC &&
st->codec->extradata_size)
st->need_parsing = AVSTREAM_PARSE_NONE;
/* AVI files with Xan DPCM audio (wrongly) declare PCM
* audio in the header but have Axan as stream_code_tag. */
@@ -739,8 +793,10 @@ static int avi_read_header(AVFormatContext *s)
break;
case MKTAG('i', 'n', 'd', 'x'):
i = avio_tell(pb);
if(pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX) && avi->use_odml &&
read_braindead_odml_indx(s, 0) < 0 && (s->error_recognition & AV_EF_EXPLODE))
if (pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX) &&
avi->use_odml &&
read_braindead_odml_indx(s, 0) < 0 &&
(s->error_recognition & AV_EF_EXPLODE))
goto fail;
avio_seek(pb, i + size, SEEK_SET);
break;
@@ -761,7 +817,8 @@ static int avi_read_header(AVFormatContext *s)
active.den = avio_rl32(pb);
avio_rl32(pb); // nbFieldsPerFrame
if(active_aspect.num && active_aspect.den && active.num && active.den){
if (active_aspect.num && active_aspect.den &&
active.num && active.den) {
st->sample_aspect_ratio = av_div_q(active_aspect, active);
av_dlog(s, "vprp %d/%d %d/%d\n",
active_aspect.num, active_aspect.den,
@@ -780,7 +837,8 @@ static int avi_read_header(AVFormatContext *s)
}
default:
if (size > 1000000) {
av_log(s, AV_LOG_ERROR, "Something went wrong during header parsing, "
av_log(s, AV_LOG_ERROR,
"Something went wrong during header parsing, "
"I will ignore it and try to continue anyway.\n");
if (s->error_recognition & AV_EF_EXPLODE)
goto fail;
@@ -794,9 +852,11 @@ static int avi_read_header(AVFormatContext *s)
break;
}
}
end_of_header:
/* check stream number */
if (stream_index != s->nb_streams - 1) {
fail:
return AVERROR_INVALIDDATA;
}
@@ -825,7 +885,8 @@ static int avi_read_header(AVFormatContext *s)
if (avi->dv_demux)
avi->non_interleaved = 0;
if (i == s->nb_streams && avi->non_interleaved) {
av_log(s, AV_LOG_WARNING, "non-interleaved AVI without index, switching to interleaved\n");
av_log(s, AV_LOG_WARNING,
"Non-interleaved AVI without index, switching to interleaved\n");
avi->non_interleaved = 0;
}
@@ -840,7 +901,8 @@ static int avi_read_header(AVFormatContext *s)
return 0;
}
static int read_gab2_sub(AVStream *st, AVPacket *pkt) {
static int read_gab2_sub(AVStream *st, AVPacket *pkt)
{
if (pkt->data && !strcmp(pkt->data, "GAB2") && AV_RL16(pkt->data + 5) == 2) {
uint8_t desc[256];
int score = AVPROBE_SCORE_EXTENSION, ret;
@@ -864,7 +926,8 @@ static int read_gab2_sub(AVStream *st, AVPacket *pkt) {
avio_rl16(pb); /* flags? */
avio_rl32(pb); /* data size */
pd = (AVProbeData) { .buf = pb->buf_ptr, .buf_size = pb->buf_end - pb->buf_ptr };
pd = (AVProbeData) { .buf = pb->buf_ptr,
.buf_size = pb->buf_end - pb->buf_ptr };
if (!(sub_demuxer = av_probe_input_format2(&pd, 1, &score)))
goto error;
@@ -882,6 +945,7 @@ static int read_gab2_sub(AVStream *st, AVPacket *pkt) {
ast->sub_buffer = pkt->data;
memset(pkt, 0, sizeof(*pkt));
return 1;
error:
av_freep(&pb);
}
@@ -915,15 +979,17 @@ static AVStream *get_subtitle_pkt(AVFormatContext *s, AVStream *next_st,
ast = sub_st->priv_data;
*pkt = ast->sub_pkt;
pkt->stream_index = sub_st->index;
if (ff_read_packet(ast->sub_ctx, &ast->sub_pkt) < 0)
ast->sub_pkt.data = NULL;
}
return sub_st;
}
static int get_stream_idx(int *d){
if( d[0] >= '0' && d[0] <= '9'
&& d[1] >= '0' && d[1] <= '9'){
static int get_stream_idx(int *d)
{
if (d[0] >= '0' && d[0] <= '9' &&
d[1] >= '0' && d[1] <= '9') {
return (d[0] - '0') * 10 + (d[1] - '0');
} else {
return 100; // invalid stream ID
@@ -961,10 +1027,10 @@ start_sync:
continue;
// parse ix##
if( (d[0] == 'i' && d[1] == 'x' && n < s->nb_streams)
if ((d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) ||
// parse JUNK
||(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K')
||(d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1')){
(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K') ||
(d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1')) {
avio_skip(pb, size);
goto start_sync;
}
@@ -977,7 +1043,8 @@ start_sync:
n = get_stream_idx(d);
if(!((i-avi->last_pkt_pos)&1) && get_stream_idx(d+1) < s->nb_streams)
if (!((i - avi->last_pkt_pos) & 1) &&
get_stream_idx(d + 1) < s->nb_streams)
continue;
// detect ##ix chunk and skip
@@ -1012,13 +1079,13 @@ start_sync:
n = 1;
st = st1;
ast = ast1;
av_log(s, AV_LOG_WARNING, "Invalid stream + prefix combination, assuming audio.\n");
av_log(s, AV_LOG_WARNING,
"Invalid stream + prefix combination, assuming audio.\n");
}
}
if ((st->discard >= AVDISCARD_DEFAULT && size == 0)
/*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & AV_PKT_FLAG_KEY))*/ //FIXME needs a little reordering
/* || (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & AV_PKT_FLAG_KEY)) */ // FIXME: needs a little reordering
|| st->discard >= AVDISCARD_ALL) {
if (!exit_early) {
ast->frame_offset += get_duration(ast, size);
@@ -1033,15 +1100,17 @@ start_sync:
avio_rl16(pb); // flags
// b + (g << 8) + (r << 16);
for (; k <= last; k++)
ast->pal[k] = 0xFFU<<24 | avio_rb32(pb)>>8;// b + (g << 8) + (r << 16);
ast->pal[k] = 0xFFU<<24 | avio_rb32(pb)>>8;
ast->has_pal = 1;
goto start_sync;
} else if( ((ast->prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) ||
} else if (((ast->prefix_count < 5 || sync + 9 > i) &&
d[2] < 128 && d[3] < 128) ||
d[2] * 256 + d[3] == ast->prefix /* ||
(d[2] == 'd' && d[3] == 'c') ||
(d[2] == 'w' && d[3] == 'b') */) {
if (exit_early)
return 0;
if (d[2] * 256 + d[3] == ast->prefix)
@@ -1057,8 +1126,10 @@ start_sync:
if (size || !ast->sample_size) {
uint64_t pos = avio_tell(pb) - 8;
if(!st->index_entries || !st->nb_index_entries || st->index_entries[st->nb_index_entries - 1].pos < pos){
av_add_index_entry(st, pos, ast->frame_offset, size, 0, AVINDEX_KEYFRAME);
if (!st->index_entries || !st->nb_index_entries ||
st->index_entries[st->nb_index_entries - 1].pos < pos) {
av_add_index_entry(st, pos, ast->frame_offset, size,
0, AVINDEX_KEYFRAME);
}
}
return 0;
@@ -1106,7 +1177,9 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
if (!ast->remaining && ts > last_ts)
continue;
ts = av_rescale_q(ts, st->time_base, (AVRational){FFMAX(1, ast->sample_size), AV_TIME_BASE});
ts = av_rescale_q(ts, st->time_base,
(AVRational) { FFMAX(1, ast->sample_size),
AV_TIME_BASE });
av_dlog(s, "%"PRId64" %d/%d %"PRId64"\n", ts,
st->time_base.num, st->time_base.den, ast->frame_offset);
@@ -1121,9 +1194,12 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
best_ast = best_st->priv_data;
best_ts = best_ast->frame_offset;
if(best_ast->remaining)
i= av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);
else{
if (best_ast->remaining) {
i = av_index_search_timestamp(best_st,
best_ts,
AVSEEK_FLAG_ANY |
AVSEEK_FLAG_BACKWARD);
} else {
i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY);
if (i >= 0)
best_ast->frame_offset = best_st->index_entries[i].timestamp;
@@ -1155,7 +1231,8 @@ resync:
if (get_subtitle_pkt(s, st, pkt))
return 0;
if(ast->sample_size <= 1) // minorityreport.AVI block_align=1024 sample_size=1 IMA-ADPCM
// minorityreport.AVI block_align=1024 sample_size=1 IMA-ADPCM
if (ast->sample_size <= 1)
size = INT_MAX;
else if (ast->sample_size < 32)
// arbitrary multiplier to avoid tiny packets for raw PCM data
@@ -1173,9 +1250,12 @@ resync:
if (ast->has_pal && pkt->size < (unsigned)INT_MAX / 2) {
uint8_t *pal;
pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE);
pal = av_packet_new_side_data(pkt,
AV_PKT_DATA_PALETTE,
AVPALETTE_SIZE);
if (!pal) {
av_log(s, AV_LOG_ERROR, "Failed to allocate data for palette\n");
av_log(s, AV_LOG_ERROR,
"Failed to allocate data for palette\n");
} else {
memcpy(pal, ast->pal, AVPALETTE_SIZE);
ast->has_pal = 0;
@@ -1196,8 +1276,8 @@ resync:
pkt->flags |= AV_PKT_FLAG_KEY;
if (size < 0)
av_free_packet(pkt);
} else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE
&& !st->codec->codec_tag && read_gab2_sub(st, pkt)) {
} else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE &&
!st->codec->codec_tag && read_gab2_sub(st, pkt)) {
ast->frame_offset++;
avi->stream_index = -1;
ast->remaining = 0;
@@ -1208,9 +1288,17 @@ resync:
// pkt->dts += ast->start;
if (ast->sample_size)
pkt->dts /= ast->sample_size;
av_dlog(s, "dts:%"PRId64" offset:%"PRId64" %d/%d smpl_siz:%d base:%d st:%d size:%d\n",
pkt->dts, ast->frame_offset, ast->scale, ast->rate,
ast->sample_size, AV_TIME_BASE, avi->stream_index, size);
av_dlog(s,
"dts:%"PRId64" offset:%"PRId64" %d/%d smpl_siz:%d "
"base:%d st:%d size:%d\n",
pkt->dts,
ast->frame_offset,
ast->scale,
ast->rate,
ast->sample_size,
AV_TIME_BASE,
avi->stream_index,
size);
pkt->stream_index = avi->stream_index;
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
@@ -1278,7 +1366,7 @@ resync:
}
/* XXX: We make the implicit supposition that the positions are sorted
for each stream. */
* for each stream. */
static int avi_read_idx1(AVFormatContext *s, int size)
{
AVIContext *avi = s->priv_data;
@@ -1298,9 +1386,8 @@ static int avi_read_idx1(AVFormatContext *s, int size)
idx1_pos = avio_tell(pb);
avio_seek(pb, avi->movi_list + 4, SEEK_SET);
if (avi_sync(s, 1) == 0) {
if (avi_sync(s, 1) == 0)
first_packet_pos = avio_tell(pb) - 8;
}
avi->stream_index = -1;
avio_seek(pb, idx1_pos, SEEK_SET);
@@ -1322,7 +1409,7 @@ static int avi_read_idx1(AVFormatContext *s, int size)
i, tag, flags, pos, len);
index = ((tag & 0xff) - '0') * 10;
index += ((tag >> 8) & 0xff) - '0';
index += (tag >> 8 & 0xff) - '0';
if (index >= s->nb_streams)
continue;
st = s->streams[index];
@@ -1341,7 +1428,8 @@ static int avi_read_idx1(AVFormatContext *s, int size)
if (last_pos == pos)
avi->non_interleaved = 1;
if (last_idx != pos && len) {
av_add_index_entry(st, pos, ast->cum_len, len, 0, (flags&AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0);
av_add_index_entry(st, pos, ast->cum_len, len, 0,
(flags & AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0);
last_idx= pos;
}
ast->cum_len += get_duration(ast, len);
@@ -1358,7 +1446,8 @@ static int avi_read_idx1(AVFormatContext *s, int size)
return 0;
}
static int guess_ni_flag(AVFormatContext *s){
static int guess_ni_flag(AVFormatContext *s)
{
int i;
int64_t last_start = 0;
int64_t first_end = INT64_MAX;
@@ -1458,6 +1547,7 @@ static int avi_load_index(AVFormatContext *s)
if (avio_seek(pb, next, SEEK_SET) < 0)
break; // something is wrong here
}
the_end:
avio_seek(pb, pos, SEEK_SET);
return ret;
@@ -1473,7 +1563,8 @@ static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
ff_read_packet(ast2->sub_ctx, &ast2->sub_pkt);
}
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static int avi_read_seek(AVFormatContext *s, int stream_index,
int64_t timestamp, int flags)
{
AVIContext *avi = s->priv_data;
AVStream *st;
@@ -1490,7 +1581,9 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
st = s->streams[stream_index];
ast = st->priv_data;
index= av_index_search_timestamp(st, timestamp * FFMAX(ast->sample_size, 1), flags);
index = av_index_search_timestamp(st,
timestamp * FFMAX(ast->sample_size, 1),
flags);
if (index < 0) {
if (st->nb_index_entries > 0)
av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n",
@@ -1541,11 +1634,16 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
continue;
// av_assert1(st2->codec->block_align);
av_assert0((int64_t)st2->time_base.num*ast2->rate == (int64_t)st2->time_base.den*ast2->scale);
index = av_index_search_timestamp(
st2,
av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1),
flags | AVSEEK_FLAG_BACKWARD | (st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
av_assert0((int64_t)st2->time_base.num * ast2->rate ==
(int64_t)st2->time_base.den * ast2->scale);
index = av_index_search_timestamp(st2,
av_rescale_q(timestamp,
st->time_base,
st2->time_base) *
FFMAX(ast2->sample_size, 1),
flags |
AVSEEK_FLAG_BACKWARD |
(st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
if (index < 0)
index = 0;
ast2->seek_pos = st2->index_entries[index].pos;