asfdec: cosmetics, reformat ff_asf_parse_packet()
This commit is contained in:
parent
5a9567631a
commit
292a08cbab
@ -1002,12 +1002,14 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
||||
ASFStream *asf_st = 0;
|
||||
for (;;) {
|
||||
int ret;
|
||||
|
||||
if (pb->eof_reached)
|
||||
return AVERROR_EOF;
|
||||
if (asf->packet_size_left < FRAME_HEADER_SIZE
|
||||
|| asf->packet_segments < 1) {
|
||||
//asf->packet_size_left <= asf->packet_padsize) {
|
||||
|
||||
if (asf->packet_size_left < FRAME_HEADER_SIZE ||
|
||||
asf->packet_segments < 1) {
|
||||
int ret = asf->packet_size_left + asf->packet_padsize;
|
||||
|
||||
assert(ret >= 0);
|
||||
/* fail safe */
|
||||
avio_skip(pb, ret);
|
||||
@ -1023,10 +1025,10 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
||||
asf->packet_segments = 0;
|
||||
continue;
|
||||
}
|
||||
if (asf->stream_index < 0
|
||||
|| s->streams[asf->stream_index]->discard >= AVDISCARD_ALL
|
||||
|| (!asf->packet_key_frame && s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)
|
||||
) {
|
||||
if (asf->stream_index < 0 ||
|
||||
s->streams[asf->stream_index]->discard >= AVDISCARD_ALL ||
|
||||
(!asf->packet_key_frame &&
|
||||
s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)) {
|
||||
asf->packet_time_start = 0;
|
||||
/* unhandled packet (should not happen) */
|
||||
avio_skip(pb, asf->packet_frag_size);
|
||||
@ -1046,8 +1048,7 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
||||
asf->packet_obj_size = asf->packet_frag_size = avio_r8(pb);
|
||||
asf->packet_size_left--;
|
||||
asf->packet_multi_size--;
|
||||
if (asf->packet_multi_size < asf->packet_obj_size)
|
||||
{
|
||||
if (asf->packet_multi_size < asf->packet_obj_size) {
|
||||
asf->packet_time_start = 0;
|
||||
avio_skip(pb, asf->packet_multi_size);
|
||||
asf->packet_size_left -= asf->packet_multi_size;
|
||||
@ -1055,19 +1056,20 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
||||
}
|
||||
asf->packet_multi_size -= asf->packet_obj_size;
|
||||
}
|
||||
if( /*asf->packet_frag_size == asf->packet_obj_size*/
|
||||
asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size
|
||||
&& asf_st->frag_offset + asf->packet_frag_size > asf->packet_obj_size){
|
||||
if (asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size &&
|
||||
asf_st->frag_offset + asf->packet_frag_size > asf->packet_obj_size) {
|
||||
av_log(s, AV_LOG_INFO, "ignoring invalid packet_obj_size (%d %d %d %d)\n",
|
||||
asf_st->frag_offset, asf->packet_frag_size,
|
||||
asf->packet_obj_size, asf_st->pkt.size);
|
||||
asf->packet_obj_size = asf_st->pkt.size;
|
||||
}
|
||||
|
||||
if ( asf_st->pkt.size != asf->packet_obj_size
|
||||
|| asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) { //FIXME is this condition sufficient?
|
||||
if (asf_st->pkt.size != asf->packet_obj_size ||
|
||||
//FIXME is this condition sufficient?
|
||||
asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) {
|
||||
if (asf_st->pkt.data) {
|
||||
av_log(s, AV_LOG_INFO, "freeing incomplete packet size %d, new %d\n", asf_st->pkt.size, asf->packet_obj_size);
|
||||
av_log(s, AV_LOG_INFO, "freeing incomplete packet size %d, "
|
||||
"new %d\n", asf_st->pkt.size, asf->packet_obj_size);
|
||||
asf_st->frag_offset = 0;
|
||||
av_free_packet(&asf_st->pkt);
|
||||
}
|
||||
@ -1076,8 +1078,8 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
||||
asf_st->seq = asf->packet_seq;
|
||||
asf_st->pkt.dts = asf->packet_frag_timestamp - asf->hdr.preroll;
|
||||
asf_st->pkt.stream_index = asf->stream_index;
|
||||
asf_st->pkt.pos =
|
||||
asf_st->packet_pos= asf->packet_pos;
|
||||
asf_st->pkt.pos = asf_st->packet_pos = asf->packet_pos;
|
||||
|
||||
if (asf_st->pkt.data && asf_st->palette_changed) {
|
||||
uint8_t *pal;
|
||||
pal = av_packet_new_side_data(&asf_st->pkt, AV_PKT_DATA_PALETTE,
|
||||
@ -1108,8 +1110,8 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
||||
if (asf->packet_size_left < 0)
|
||||
continue;
|
||||
|
||||
if( asf->packet_frag_offset >= asf_st->pkt.size
|
||||
|| asf->packet_frag_size > asf_st->pkt.size - asf->packet_frag_offset){
|
||||
if (asf->packet_frag_offset >= asf_st->pkt.size ||
|
||||
asf->packet_frag_size > asf_st->pkt.size - asf->packet_frag_offset) {
|
||||
av_log(s, AV_LOG_ERROR, "packet fragment position invalid %u,%u not in %u\n",
|
||||
asf->packet_frag_offset, asf->packet_frag_size, asf_st->pkt.size);
|
||||
continue;
|
||||
@ -1120,6 +1122,7 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
||||
if (ret != asf->packet_frag_size) {
|
||||
if (ret < 0 || asf->packet_frag_offset + ret == 0)
|
||||
return ret < 0 ? ret : AVERROR_EOF;
|
||||
|
||||
if (asf_st->ds_span > 1) {
|
||||
// scrambling, we can either drop it completely or fill the remainder
|
||||
// TODO: should we fill the whole packet instead of just the current
|
||||
@ -1127,10 +1130,11 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
||||
memset(asf_st->pkt.data + asf->packet_frag_offset + ret, 0,
|
||||
asf->packet_frag_size - ret);
|
||||
ret = asf->packet_frag_size;
|
||||
} else
|
||||
} else {
|
||||
// no scrambling, so we can return partial packets
|
||||
av_shrink_packet(&asf_st->pkt, asf->packet_frag_offset + ret);
|
||||
}
|
||||
}
|
||||
if (s->key && s->keylen == 20)
|
||||
ff_asfcrypt_dec(s->key, asf_st->pkt.data + asf->packet_frag_offset,
|
||||
ret);
|
||||
@ -1138,8 +1142,8 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
||||
/* test if whole packet is read */
|
||||
if (asf_st->frag_offset == asf_st->pkt.size) {
|
||||
//workaround for macroshit radio DVR-MS files
|
||||
if( s->streams[asf->stream_index]->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO
|
||||
&& asf_st->pkt.size > 100){
|
||||
if (s->streams[asf->stream_index]->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO &&
|
||||
asf_st->pkt.size > 100) {
|
||||
int i;
|
||||
for (i = 0; i < asf_st->pkt.size && !asf_st->pkt.data[i]; i++);
|
||||
if (i == asf_st->pkt.size) {
|
||||
@ -1153,7 +1157,9 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
||||
/* return packet */
|
||||
if (asf_st->ds_span > 1) {
|
||||
if(asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span) {
|
||||
av_log(s, AV_LOG_ERROR, "pkt.size != ds_packet_size * ds_span (%d %d %d)\n", asf_st->pkt.size, asf_st->ds_packet_size, asf_st->ds_span);
|
||||
av_log(s, AV_LOG_ERROR, "pkt.size != ds_packet_size * "
|
||||
"ds_span (%d %d %d)\n", asf_st->pkt.size,
|
||||
asf_st->ds_packet_size, asf_st->ds_span);
|
||||
} else {
|
||||
/* packet descrambling */
|
||||
uint8_t *newdata = av_malloc(asf_st->pkt.size + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
|
Loading…
x
Reference in New Issue
Block a user