|
|
|
@ -21,6 +21,7 @@ |
|
|
|
|
|
|
|
|
|
//#define DEBUG
|
|
|
|
|
|
|
|
|
|
#include "libavutil/attributes.h" |
|
|
|
|
#include "libavutil/bswap.h" |
|
|
|
|
#include "libavutil/common.h" |
|
|
|
|
#include "libavutil/avstring.h" |
|
|
|
@ -420,9 +421,6 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) |
|
|
|
|
avio_rl16(pb); //ds_data_size
|
|
|
|
|
avio_r8(pb); //ds_silence_data
|
|
|
|
|
} |
|
|
|
|
//printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n",
|
|
|
|
|
// asf_st->ds_packet_size, asf_st->ds_chunk_size,
|
|
|
|
|
// asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data);
|
|
|
|
|
if (asf_st->ds_span > 1) { |
|
|
|
|
if (!asf_st->ds_chunk_size |
|
|
|
|
|| (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1) |
|
|
|
@ -443,7 +441,6 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) |
|
|
|
|
st->codec->bits_per_coded_sample = avio_rl16(pb); /* depth */ |
|
|
|
|
tag1 = avio_rl32(pb); |
|
|
|
|
avio_skip(pb, 20); |
|
|
|
|
// av_log(s, AV_LOG_DEBUG, "size:%d tsize:%d sizeX:%d\n", size, total_size, sizeX);
|
|
|
|
|
if (sizeX > 40) { |
|
|
|
|
st->codec->extradata_size = sizeX - 40; |
|
|
|
|
st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); |
|
|
|
@ -614,16 +611,18 @@ static int asf_read_metadata(AVFormatContext *s, int64_t size) |
|
|
|
|
|
|
|
|
|
for(i=0;i<n;i++) { |
|
|
|
|
char name[1024]; |
|
|
|
|
int av_unused value_type; |
|
|
|
|
|
|
|
|
|
avio_rl16(pb); //lang_list_index
|
|
|
|
|
stream_num= avio_rl16(pb); |
|
|
|
|
name_len= avio_rl16(pb); |
|
|
|
|
avio_skip(pb, 2); /* value_type */ |
|
|
|
|
value_type = avio_rl16(pb); /* value_type */ |
|
|
|
|
value_len= avio_rl32(pb); |
|
|
|
|
|
|
|
|
|
if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len) |
|
|
|
|
avio_skip(pb, name_len - ret); |
|
|
|
|
//av_log(s, AV_LOG_ERROR, "%d %d %d %d %d <%s>\n", i, stream_num, name_len, value_type, value_len, name);
|
|
|
|
|
av_dlog(s, "%d %d %d %d %d <%s>\n", |
|
|
|
|
i, stream_num, name_len, value_type, value_len, name); |
|
|
|
|
value_num= avio_rl16(pb);//we should use get_value() here but it does not work 2 is le16 here but le32 elsewhere
|
|
|
|
|
avio_skip(pb, value_len - 2); |
|
|
|
|
|
|
|
|
@ -689,9 +688,7 @@ static int asf_read_header(AVFormatContext *s) |
|
|
|
|
uint64_t gpos= avio_tell(pb); |
|
|
|
|
ff_get_guid(pb, &g); |
|
|
|
|
gsize = avio_rl64(pb); |
|
|
|
|
av_dlog(s, "%08"PRIx64": ", gpos); |
|
|
|
|
print_guid(&g); |
|
|
|
|
av_dlog(s, " size=0x%"PRIx64"\n", gsize); |
|
|
|
|
if (!ff_guidcmp(&g, &ff_asf_data_header)) { |
|
|
|
|
asf->data_object_offset = avio_tell(pb); |
|
|
|
|
// if not streaming, gsize is not unlimited (how?), and there is enough space in the file..
|
|
|
|
@ -784,7 +781,9 @@ static int asf_read_header(AVFormatContext *s) |
|
|
|
|
&st->sample_aspect_ratio.num, |
|
|
|
|
asf->dar[0].num, asf->dar[0].den, INT_MAX); |
|
|
|
|
|
|
|
|
|
//av_log(s, AV_LOG_INFO, "i=%d, st->codec->codec_type:%d, dar %d:%d sar=%d:%d\n", i, st->codec->codec_type, dar[i].num, dar[i].den, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
|
|
|
|
|
av_dlog(s, "i=%d, st->codec->codec_type:%d, asf->dar %d:%d sar=%d:%d\n", |
|
|
|
|
i, st->codec->codec_type, asf->dar[i].num, asf->dar[i].den, |
|
|
|
|
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); |
|
|
|
|
|
|
|
|
|
// copy and convert language codes to the frontend
|
|
|
|
|
if (asf->streams[i].stream_language_index < 128) { |
|
|
|
@ -926,7 +925,9 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){ |
|
|
|
|
DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0); |
|
|
|
|
DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0); |
|
|
|
|
DO_2BITS(asf->packet_property, asf->packet_replic_size, 0); |
|
|
|
|
//printf("key:%d stream:%d seq:%d offset:%d replic_size:%d\n", asf->packet_key_frame, asf->stream_index, asf->packet_seq, //asf->packet_frag_offset, asf->packet_replic_size);
|
|
|
|
|
av_dlog(asf, "key:%d stream:%d seq:%d offset:%d replic_size:%d\n", |
|
|
|
|
asf->packet_key_frame, asf->stream_index, asf->packet_seq, |
|
|
|
|
asf->packet_frag_offset, asf->packet_replic_size); |
|
|
|
|
if (rsize+asf->packet_replic_size > asf->packet_size_left) { |
|
|
|
|
av_log(s, AV_LOG_ERROR, "packet_replic_size %d is invalid\n", asf->packet_replic_size); |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
@ -939,9 +940,6 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){ |
|
|
|
|
} |
|
|
|
|
asf->packet_frag_timestamp = avio_rl32(pb); // timestamp
|
|
|
|
|
if(asf->packet_replic_size >= 8+38+4){ |
|
|
|
|
// for(i=0; i<asf->packet_replic_size-8; i++)
|
|
|
|
|
// av_log(s, AV_LOG_DEBUG, "%02X ",avio_r8(pb));
|
|
|
|
|
// av_log(s, AV_LOG_DEBUG, "\n");
|
|
|
|
|
avio_skip(pb, 10); |
|
|
|
|
ts0= avio_rl64(pb); |
|
|
|
|
ts1= avio_rl64(pb); |
|
|
|
@ -980,10 +978,8 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){ |
|
|
|
|
asf->packet_padsize -= diff; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//printf("Fragsize %d\n", asf->packet_frag_size);
|
|
|
|
|
} else { |
|
|
|
|
asf->packet_frag_size = asf->packet_size_left - rsize; |
|
|
|
|
//printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
|
|
|
|
|
} |
|
|
|
|
if (asf->packet_replic_size == 1) { |
|
|
|
|
asf->packet_multi_size = asf->packet_frag_size; |
|
|
|
@ -991,7 +987,6 @@ static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){ |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
asf->packet_size_left -= rsize; |
|
|
|
|
//printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
@ -1017,7 +1012,6 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk |
|
|
|
|
|| asf->packet_segments < 1) { |
|
|
|
|
//asf->packet_size_left <= asf->packet_padsize) {
|
|
|
|
|
int ret = asf->packet_size_left + asf->packet_padsize; |
|
|
|
|
//printf("PacketLeftSize:%d Pad:%d Pos:%"PRId64"\n", asf->packet_size_left, asf->packet_padsize, avio_tell(pb));
|
|
|
|
|
assert(ret>=0); |
|
|
|
|
/* fail safe */ |
|
|
|
|
avio_skip(pb, ret); |
|
|
|
@ -1064,7 +1058,6 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
asf->packet_multi_size -= asf->packet_obj_size; |
|
|
|
|
//printf("COMPRESS size %d %d %d ms:%d\n", asf->packet_obj_size, asf->packet_frag_timestamp, asf->packet_size_left, asf->packet_multi_size);
|
|
|
|
|
} |
|
|
|
|
if( /*asf->packet_frag_size == asf->packet_obj_size*/ |
|
|
|
|
asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size |
|
|
|
@ -1100,9 +1093,11 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk |
|
|
|
|
asf_st->palette_changed = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//printf("new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n",
|
|
|
|
|
//asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & AV_PKT_FLAG_KEY,
|
|
|
|
|
//s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO, asf->packet_obj_size);
|
|
|
|
|
av_dlog(asf, "new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n", |
|
|
|
|
asf->stream_index, asf->packet_key_frame, |
|
|
|
|
asf_st->pkt.flags & AV_PKT_FLAG_KEY, |
|
|
|
|
s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO, |
|
|
|
|
asf->packet_obj_size); |
|
|
|
|
if (s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO) |
|
|
|
|
asf->packet_key_frame = 1; |
|
|
|
|
if (asf->packet_key_frame) |
|
|
|
@ -1110,9 +1105,9 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* read data */ |
|
|
|
|
//printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
|
|
|
|
|
// s->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
|
|
|
|
|
// asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
|
|
|
|
|
av_dlog(asf, "READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n", |
|
|
|
|
s->packet_size, asf_st->pkt.size, asf->packet_frag_offset, |
|
|
|
|
asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data); |
|
|
|
|
asf->packet_size_left -= asf->packet_frag_size; |
|
|
|
|
if (asf->packet_size_left < 0) |
|
|
|
|
continue; |
|
|
|
@ -1174,8 +1169,6 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk |
|
|
|
|
int row = off / asf_st->ds_span; |
|
|
|
|
int col = off % asf_st->ds_span; |
|
|
|
|
int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size; |
|
|
|
|
//printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx);
|
|
|
|
|
|
|
|
|
|
assert(offset + asf_st->ds_chunk_size <= asf_st->pkt.size); |
|
|
|
|
assert(idx+1 <= asf_st->pkt.size / asf_st->ds_chunk_size); |
|
|
|
|
memcpy(newdata + offset, |
|
|
|
@ -1190,7 +1183,6 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk |
|
|
|
|
} |
|
|
|
|
asf_st->frag_offset = 0; |
|
|
|
|
*pkt= asf_st->pkt; |
|
|
|
|
//printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size);
|
|
|
|
|
asf_st->pkt.size = 0; |
|
|
|
|
asf_st->pkt.data = 0; |
|
|
|
|
asf_st->pkt.side_data_elems = 0; |
|
|
|
@ -1280,7 +1272,6 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, |
|
|
|
|
if (avio_seek(s->pb, pos, SEEK_SET) < 0) |
|
|
|
|
return AV_NOPTS_VALUE; |
|
|
|
|
|
|
|
|
|
//printf("asf_read_pts\n");
|
|
|
|
|
asf_reset_header(s); |
|
|
|
|
for(;;){ |
|
|
|
|
if (av_read_frame(s, pkt) < 0){ |
|
|
|
@ -1308,8 +1299,6 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
*ppos= pos; |
|
|
|
|
//printf("found keyframe at %"PRId64" stream %d stamp:%"PRId64"\n", *ppos, stream_index, pts);
|
|
|
|
|
|
|
|
|
|
return pts; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|