/**********************************/
/* decoding */
-static int guidcmp(const void *g1, const void *g2)
+int ff_guidcmp(const void *g1, const void *g2)
{
return memcmp(g1, g2, sizeof(ff_asf_guid));
}
#ifdef DEBUG
#define PRINT_IF_GUID(g,cmp) \
-if (!guidcmp(g, &cmp)) \
+if (!ff_guidcmp(g, &cmp)) \
dprintf(NULL, "(GUID: %s) ", #cmp)
static void print_guid(const ff_asf_guid *g)
#define print_guid(g)
#endif
-static void get_guid(ByteIOContext *s, ff_asf_guid *g)
+void ff_get_guid(ByteIOContext *s, ff_asf_guid *g)
{
assert(sizeof(*g) == 16);
get_buffer(s, *g, sizeof(*g));
static int asf_probe(AVProbeData *pd)
{
/* check file header */
- if (!guidcmp(pd->buf, &ff_asf_header))
+ if (!ff_guidcmp(pd->buf, &ff_asf_header))
return AVPROBE_SCORE_MAX;
else
return 0;
memset(dar, 0, sizeof(dar));
memset(bitrate, 0, sizeof(bitrate));
- get_guid(pb, &g);
- if (guidcmp(&g, &ff_asf_header))
+ ff_get_guid(pb, &g);
+ if (ff_guidcmp(&g, &ff_asf_header))
return -1;
get_le64(pb);
get_le32(pb);
memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
for(;;) {
uint64_t gpos= url_ftell(pb);
- get_guid(pb, &g);
+ ff_get_guid(pb, &g);
gsize = get_le64(pb);
dprintf(s, "%08"PRIx64": ", gpos);
print_guid(&g);
dprintf(s, " size=0x%"PRIx64"\n", gsize);
- if (!guidcmp(&g, &ff_asf_data_header)) {
+ if (!ff_guidcmp(&g, &ff_asf_data_header)) {
asf->data_object_offset = url_ftell(pb);
// if not streaming, gsize is not unlimited (how?), and there is enough space in the file..
if (!(asf->hdr.flags & 0x01) && gsize >= 100) {
}
if (gsize < 24)
return -1;
- if (!guidcmp(&g, &ff_asf_file_header)) {
- get_guid(pb, &asf->hdr.guid);
+ if (!ff_guidcmp(&g, &ff_asf_file_header)) {
+ ff_get_guid(pb, &asf->hdr.guid);
asf->hdr.file_size = get_le64(pb);
asf->hdr.create_time = get_le64(pb);
asf->nb_packets = get_le64(pb);
asf->hdr.max_pktsize = get_le32(pb);
asf->hdr.max_bitrate = get_le32(pb);
s->packet_size = asf->hdr.max_pktsize;
- } else if (!guidcmp(&g, &ff_asf_stream_header)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_stream_header)) {
enum AVMediaType type;
int type_specific_size, sizeX;
uint64_t total_size;
st->duration = asf->hdr.play_time /
(10000000 / 1000) - start_time;
}
- get_guid(pb, &g);
+ ff_get_guid(pb, &g);
test_for_ext_stream_audio = 0;
- if (!guidcmp(&g, &ff_asf_audio_stream)) {
+ if (!ff_guidcmp(&g, &ff_asf_audio_stream)) {
type = AVMEDIA_TYPE_AUDIO;
- } else if (!guidcmp(&g, &ff_asf_video_stream)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_video_stream)) {
type = AVMEDIA_TYPE_VIDEO;
- } else if (!guidcmp(&g, &ff_asf_jfif_media)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_jfif_media)) {
type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = CODEC_ID_MJPEG;
- } else if (!guidcmp(&g, &ff_asf_command_stream)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_command_stream)) {
type = AVMEDIA_TYPE_DATA;
- } else if (!guidcmp(&g, &ff_asf_ext_stream_embed_stream_header)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_embed_stream_header)) {
test_for_ext_stream_audio = 1;
type = AVMEDIA_TYPE_UNKNOWN;
} else {
return -1;
}
- get_guid(pb, &g);
+ ff_get_guid(pb, &g);
total_size = get_le64(pb);
type_specific_size = get_le32(pb);
get_le32(pb);
get_le32(pb);
if (test_for_ext_stream_audio) {
- get_guid(pb, &g);
- if (!guidcmp(&g, &ff_asf_ext_stream_audio_stream)) {
+ ff_get_guid(pb, &g);
+ if (!ff_guidcmp(&g, &ff_asf_ext_stream_audio_stream)) {
type = AVMEDIA_TYPE_AUDIO;
is_dvr_ms_audio=1;
- get_guid(pb, &g);
+ ff_get_guid(pb, &g);
get_le32(pb);
get_le32(pb);
get_le32(pb);
- get_guid(pb, &g);
+ ff_get_guid(pb, &g);
get_le32(pb);
}
}
}
pos2 = url_ftell(pb);
url_fskip(pb, gsize - (pos2 - pos1 + 24));
- } else if (!guidcmp(&g, &ff_asf_comment_header)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_comment_header)) {
int len1, len2, len3, len4, len5;
len1 = get_le16(pb);
get_tag(s, "copyright", 0, len3);
get_tag(s, "comment" , 0, len4);
url_fskip(pb, len5);
- } else if (!guidcmp(&g, &stream_bitrate_guid)) {
+ } else if (!ff_guidcmp(&g, &stream_bitrate_guid)) {
int stream_count = get_le16(pb);
int j;
// av_log(s, AV_LOG_ERROR, "flags: 0x%x stream id %d, bitrate %d\n", flags, stream_id, bitrate);
asf->stream_bitrates[stream_id]= bitrate;
}
- } else if (!guidcmp(&g, &ff_asf_language_guid)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_language_guid)) {
int j;
int stream_count = get_le16(pb);
for(j = 0; j < stream_count; j++) {
if (j < 128)
av_strlcpy(asf->stream_languages[j], lang, sizeof(*asf->stream_languages));
}
- } else if (!guidcmp(&g, &ff_asf_extended_content_header)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_extended_content_header)) {
int desc_count, i;
desc_count = get_le16(pb);
value_len = get_le16(pb);
if (!value_type && value_len%2)
value_len += 1;
- get_tag(s, name, value_type, value_len);
+ /**
+ * My sample has that stream set to 0 maybe that mean the container.
+ * Asf stream count start at 1. I am using 0 to the container value since it's unused
+ */
+ if (!strcmp(name, "AspectRatioX")){
+ dar[0].num= get_value(s->pb, value_type);
+ } else if(!strcmp(name, "AspectRatioY")){
+ dar[0].den= get_value(s->pb, value_type);
+ } else
+ get_tag(s, name, value_type, value_len);
}
- } else if (!guidcmp(&g, &ff_asf_metadata_header)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_metadata_header)) {
int n, stream_num, name_len, value_len, value_type, value_num;
n = get_le16(pb);
else if(!strcmp(name, "AspectRatioY")) dar[stream_num].den= value_num;
}
}
- } else if (!guidcmp(&g, &ff_asf_ext_stream_header)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_header)) {
int ext_len, payload_ext_ct, stream_ct;
uint32_t ext_d, leak_rate, stream_num;
unsigned int stream_languageid_index;
}
for (i=0; i<payload_ext_ct; i++){
- get_guid(pb, &g);
+ ff_get_guid(pb, &g);
ext_d=get_le16(pb);
ext_len=get_le32(pb);
url_fseek(pb, ext_len, SEEK_CUR);
// there could be a optional stream properties object to follow
// if so the next iteration will pick it up
continue;
- } else if (!guidcmp(&g, &ff_asf_head1_guid)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_head1_guid)) {
int v1, v2;
- get_guid(pb, &g);
+ ff_get_guid(pb, &g);
v1 = get_le32(pb);
v2 = get_le16(pb);
continue;
- } else if (!guidcmp(&g, &ff_asf_marker_header)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_marker_header)) {
int i, count, name_len;
char name[1024];
ff_new_chapter(s, i, (AVRational){1, 10000000}, pres_time, AV_NOPTS_VALUE, name );
}
#if 0
- } else if (!guidcmp(&g, &ff_asf_codec_comment_header)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_codec_comment_header)) {
int len, v1, n, num;
char str[256], *q;
char tag[16];
- get_guid(pb, &g);
+ ff_get_guid(pb, &g);
print_guid(&g);
n = get_le32(pb);
return -1;
} else {
if (!s->keylen) {
- if (!guidcmp(&g, &ff_asf_content_encryption)) {
+ if (!ff_guidcmp(&g, &ff_asf_content_encryption)) {
av_log(s, AV_LOG_WARNING, "DRM protected stream detected, decoding will likely fail!\n");
- } else if (!guidcmp(&g, &ff_asf_ext_content_encryption)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_ext_content_encryption)) {
av_log(s, AV_LOG_WARNING, "Ext DRM protected stream detected, decoding will likely fail!\n");
- } else if (!guidcmp(&g, &ff_asf_digital_signature)) {
+ } else if (!ff_guidcmp(&g, &ff_asf_digital_signature)) {
av_log(s, AV_LOG_WARNING, "Digital signature detected, decoding will likely fail!\n");
}
}
av_log(s, AV_LOG_DEBUG, "gpos mismatch our pos=%"PRIu64", end=%"PRIu64"\n", url_ftell(pb)-gpos, gsize);
url_fseek(pb, gpos + gsize, SEEK_SET);
}
- get_guid(pb, &g);
+ ff_get_guid(pb, &g);
get_le64(pb);
get_byte(pb);
get_byte(pb);
AVStream *st = s->streams[stream_num];
if (!st->codec->bit_rate)
st->codec->bit_rate = bitrate[i];
- if (dar[i].num > 0 && dar[i].den > 0)
+ if (dar[i].num > 0 && dar[i].den > 0){
av_reduce(&st->sample_aspect_ratio.num,
&st->sample_aspect_ratio.den,
dar[i].num, dar[i].den, INT_MAX);
-//av_log(s, AV_LOG_ERROR, "dar %d:%d sar=%d:%d\n", dar[i].num, dar[i].den, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
+ } else if ((dar[0].num > 0) && (dar[0].den > 0) && (st->codec->codec_type==AVMEDIA_TYPE_VIDEO)) // Use ASF container value if the stream doesn't AR set.
+ av_reduce(&st->sample_aspect_ratio.num,
+ &st->sample_aspect_ratio.den,
+ dar[0].num, 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);
// copy and convert language codes to the frontend
if (asf->streams[i].stream_language_index < 128) {
}
}
+ ff_metadata_conv(&s->metadata, NULL, ff_asf_metadata_conv);
+
return 0;
}
ASFContext *asf = s->priv_data;
ASFStream *asf_st = 0;
for (;;) {
+ int ret;
if(url_feof(pb))
return AVERROR_EOF;
if (asf->packet_size_left < FRAME_HEADER_SIZE
continue;
}
- get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
- asf->packet_frag_size);
+ ret = get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
+ asf->packet_frag_size);
+ 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
+ // fragment?
+ memset(asf_st->pkt.data + asf->packet_frag_offset + ret, 0,
+ asf->packet_frag_size - ret);
+ ret = asf->packet_frag_size;
+ } 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,
- asf->packet_frag_size);
- asf_st->frag_offset += asf->packet_frag_size;
+ ret);
+ asf_st->frag_offset += ret;
/* test if whole packet is read */
if (asf_st->frag_offset == asf_st->pkt.size) {
//workaround for macroshit radio DVR-MS files
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);
+ uint8_t *newdata = av_malloc(asf_st->pkt.size + FF_INPUT_BUFFER_PADDING_SIZE);
if (newdata) {
int offset = 0;
+ memset(newdata + asf_st->pkt.size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
while (offset < asf_st->pkt.size) {
int off = offset / asf_st->ds_chunk_size;
int row = off / asf_st->ds_span;
int i;
url_fseek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET);
- get_guid(s->pb, &g);
- if (!guidcmp(&g, &index_guid)) {
+ ff_get_guid(s->pb, &g);
+
+ /* the data object can be followed by other top-level objects,
+ skip them until the simple index object is reached */
+ while (ff_guidcmp(&g, &index_guid)) {
+ int64_t gsize= get_le64(s->pb);
+ if (gsize < 24 || url_feof(s->pb)) {
+ url_fseek(s->pb, current_pos, SEEK_SET);
+ return;
+ }
+ url_fseek(s->pb, gsize-24, SEEK_CUR);
+ ff_get_guid(s->pb, &g);
+ }
+
+ {
int64_t itime, last_pos=-1;
int pct, ict;
int64_t av_unused gsize= get_le64(s->pb);
- get_guid(s->pb, &g);
+ ff_get_guid(s->pb, &g);
itime=get_le64(s->pb);
pct=get_le32(s->pb);
ict=get_le32(s->pb);
asf_read_close,
asf_read_seek,
asf_read_pts,
- .metadata_conv = ff_asf_metadata_conv,
};