42 #define ASF_UNICODE 0x0
43 #define ASF_FLAG_BROADCAST 0x1
44 #define ASF_BYTE_ARRAY 0x1
45 #define ASF_TYPE_AUDIO 0x2
46 #define ASF_TYPE_VIDEO 0x1
47 #define ASF_STREAM_NUM 0x7F
48 #define ASF_MAX_STREAMS 128
49 #define BMP_HEADER_SIZE 40
50 #define ASF_NUM_OF_PAYLOADS 0x3F
51 #define ASF_ERROR_CORRECTION_LENGTH_TYPE 0x60
52 #define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE 0x2
157 FFSWAP(
unsigned char, guid[0], guid[3]);
158 FFSWAP(
unsigned char, guid[1], guid[2]);
159 FFSWAP(
unsigned char, guid[4], guid[5]);
160 FFSWAP(
unsigned char, guid[6], guid[7]);
176 if (
size > INT64_MAX)
182 if (!
g->is_subobject) {
183 if (!(
ret = strcmp(
g->name,
"Header Extension")))
205 while (
ret + 1 < maxlen) {
221 int i, nb_markers,
ret;
233 for (
i = 0;
i < nb_markers;
i++) {
259 unsigned char *ch, uint16_t buflen)
277 uint16_t buflen = 2 * val_len + 1;
291 if (val_len >
sizeof(buf)) {
297 if (
ret < 2 * val_len)
300 value[2 * val_len - 1] =
'\0';
391 for (
i = 0;
i < nb_desc;
i++) {
392 uint16_t name_len,
type, val_len;
448 if (!strcmp(
name,
"AspectRatioX"))
464 for (
i = 0;
i < nb_recs;
i++) {
465 uint16_t name_len, buflen,
type, val_len, st_num;
471 buflen = 2 * name_len + 1;
481 if (!strcmp(
name,
"AspectRatioX") || !strcmp(
name,
"AspectRatioY")) {
491 : &
s->metadata)) < 0) {
509 static const char *
const titles[] =
510 {
"Title",
"Author",
"Copyright",
"Description",
"Rate" };
511 uint16_t
len[5], buflen[5] = { 0 };
515 for (
i = 0;
i < 5;
i++) {
518 buflen[
i] = 2 *
len[
i] + 1;
521 for (
i = 0;
i < 5;
i++) {
537 time_t creation_time;
549 creation_time /= 10000000;
551 creation_time -= 11644473600;
552 tm =
gmtime_r(&creation_time, &tmbuf);
554 if (!strftime(buf,
sizeof(buf),
"%Y-%m-%d %H:%M:%S", tm))
559 if (
av_dict_set(&
s->metadata,
"creation_time", buf, 0) < 0)
589 size_bmp =
FFMAX(size_asf, size_bmp);
605 uint32_t err_data_len, ts_data_len;
610 uint8_t stream_index;
644 "Duplicate stream found, this stream will be ignored.\n");
663 asf_st->
pkt.data_size = 0;
665 if (!asf_st->
pkt.avpkt)
709 if (rfc1766 && strlen(rfc1766) > 1) {
710 const char primary_tag[3] = { rfc1766[0], rfc1766[1],
'\0' };
725 uint16_t nb_st_name, nb_pay_exts, st_num, lang_idx;
728 uint64_t
start_time, end_time, time_per_frame;
757 for (
i = 0;
i < nb_st_name;
i++) {
765 for (
i = 0;
i < nb_pay_exts;
i++) {
780 if (
g && !(strcmp(
g->name,
"Stream Properties"))) {
781 if ((
ret =
g->read_object(
s,
g)) < 0)
798 for (
i = 0;
i < nb_langs;
i++) {
833 asf->
state = PARSE_PACKET_HEADER;
840 "Number of Packets from File Properties Object is not equal to Total"
841 "Datapackets value! num of packets %"PRIu64
" total num %"PRIu64
".\n",
857 uint32_t pkt_num, nb_entries;
880 for (
i = 0;
i < nb_entries;
i++) {
887 if (prev_pkt_num != pkt_num) {
891 prev_pkt_num = pkt_num;
901 {
"Data", { 0x75, 0xB2, 0x26, 0x36, 0x66, 0x8E, 0x11, 0xCF, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C },
asf_read_data, 1 },
902 {
"Simple Index", { 0x33, 0x00, 0x08, 0x90, 0xE5, 0xB1, 0x11, 0xCF, 0x89, 0xF4, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB },
asf_read_simple_index, 1 },
903 {
"Content Description", { 0x75, 0xB2, 0x26, 0x33, 0x66 ,0x8E, 0x11, 0xCF, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C },
asf_read_content_desc, 1 },
904 {
"Extended Content Description", { 0xD2, 0xD0, 0xA4, 0x40, 0xE3, 0x07, 0x11, 0xD2, 0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5e, 0xA8, 0x50 },
asf_read_ext_content, 1 },
905 {
"Stream Bitrate Properties", { 0x7B, 0xF8, 0x75, 0xCE, 0x46, 0x8D, 0x11, 0xD1, 0x8D, 0x82, 0x00, 0x60, 0x97, 0xC9, 0xA2, 0xB2 },
asf_read_unknown, 1 },
906 {
"File Properties", { 0x8C, 0xAB, 0xDC, 0xA1, 0xA9, 0x47, 0x11, 0xCF, 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
asf_read_properties, 1 },
907 {
"Header Extension", { 0x5F, 0xBF, 0x03, 0xB5, 0xA9, 0x2E, 0x11, 0xCF, 0x8E, 0xE3, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
asf_read_unknown, 0 },
908 {
"Stream Properties", { 0xB7, 0xDC, 0x07, 0x91, 0xA9, 0xB7, 0x11, 0xCF, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
asf_read_stream_properties, 1 },
909 {
"Codec List", { 0x86, 0xD1, 0x52, 0x40, 0x31, 0x1D, 0x11, 0xD0, 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 },
asf_read_unknown, 1 },
910 {
"Marker", { 0xF4, 0x87, 0xCD, 0x01, 0xA9, 0x51, 0x11, 0xCF, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
asf_read_marker, 1 },
911 {
"Script Command", { 0x1E, 0xFB, 0x1A, 0x30, 0x0B, 0x62, 0x11, 0xD0, 0xA3, 0x9B, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 },
asf_read_unknown, 1 },
912 {
"Language List", { 0x7C, 0x43, 0x46, 0xa9, 0xef, 0xe0, 0x4B, 0xFC, 0xB2, 0x29, 0x39, 0x3e, 0xde, 0x41, 0x5c, 0x85 },
asf_read_language_list, 1},
913 {
"Padding", { 0x18, 0x06, 0xD4, 0x74, 0xCA, 0xDF, 0x45, 0x09, 0xA4, 0xBA, 0x9A, 0xAB, 0xCB, 0x96, 0xAA, 0xE8 },
asf_read_unknown, 1 },
914 {
"DRMv1 Header", { 0x22, 0x11, 0xB3, 0xFB, 0xBD, 0x23, 0x11, 0xD2, 0xB4, 0xB7, 0x00, 0xA0, 0xC9, 0x55, 0xFC, 0x6E },
asf_read_unknown, 1 },
915 {
"DRMv2 Header", { 0x29, 0x8A, 0xE6, 0x14, 0x26, 0x22, 0x4C, 0x17, 0xB9, 0x35, 0xDA, 0xE0, 0x7E, 0xE9, 0x28, 0x9c },
asf_read_unknown, 1 },
916 {
"Index", { 0xD6, 0xE2, 0x29, 0xD3, 0x35, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE },
asf_read_unknown, 1 },
917 {
"Media Object Index", { 0xFE, 0xB1, 0x03, 0xF8, 0x12, 0xAD, 0x4C, 0x64, 0x84, 0x0F, 0x2A, 0x1D, 0x2F, 0x7A, 0xD4, 0x8C },
asf_read_unknown, 1 },
918 {
"Timecode Index", { 0x3C, 0xB7, 0x3F, 0xD0, 0x0C, 0x4A, 0x48, 0x03, 0x95, 0x3D, 0xED, 0xF7, 0xB6, 0x22, 0x8F, 0x0C },
asf_read_unknown, 0 },
919 {
"Bitrate_Mutual_Exclusion", { 0xD6, 0xE2, 0x29, 0xDC, 0x35, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE },
asf_read_unknown, 1 },
920 {
"Error Correction", { 0x75, 0xB2, 0x26, 0x35, 0x66, 0x8E, 0x11, 0xCF, 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C },
asf_read_unknown, 1 },
921 {
"Content Branding", { 0x22, 0x11, 0xB3, 0xFA, 0xBD, 0x23, 0x11, 0xD2, 0xB4, 0xB7, 0x00, 0xA0, 0xC9, 0x55, 0xFC, 0x6E },
asf_read_unknown, 1 },
922 {
"Content Encryption", { 0x22, 0x11, 0xB3, 0xFB, 0xBD, 0x23, 0x11, 0xD2, 0xB4, 0xB7, 0x00, 0xA0, 0xC9, 0x55, 0xFC, 0x6E },
asf_read_unknown, 1 },
923 {
"Extended Content Encryption", { 0x29, 0x8A, 0xE6, 0x14, 0x26, 0x22, 0x4C, 0x17, 0xB9, 0x35, 0xDA, 0xE0, 0x7E, 0xE9, 0x28, 0x9C },
asf_read_unknown, 1 },
924 {
"Digital Signature", { 0x22, 0x11, 0xB3, 0xFC, 0xBD, 0x23, 0x11, 0xD2, 0xB4, 0xB7, 0x00, 0xA0, 0xC9, 0x55, 0xFC, 0x6E },
asf_read_unknown, 1 },
925 {
"Extended Stream Properties", { 0x14, 0xE6, 0xA5, 0xCB, 0xC6, 0x72, 0x43, 0x32, 0x83, 0x99, 0xA9, 0x69, 0x52, 0x06, 0x5B, 0x5A },
asf_read_ext_stream_properties, 1 },
926 {
"Advanced Mutual Exclusion", { 0xA0, 0x86, 0x49, 0xCF, 0x47, 0x75, 0x46, 0x70, 0x8A, 0x16, 0x6E, 0x35, 0x35, 0x75, 0x66, 0xCD },
asf_read_unknown, 1 },
927 {
"Group Mutual Exclusion", { 0xD1, 0x46, 0x5A, 0x40, 0x5A, 0x79, 0x43, 0x38, 0xB7, 0x1B, 0xE3, 0x6B, 0x8F, 0xD6, 0xC2, 0x49 },
asf_read_unknown, 1},
928 {
"Stream Prioritization", { 0xD4, 0xFE, 0xD1, 0x5B, 0x88, 0xD3, 0x45, 0x4F, 0x81, 0xF0, 0xED, 0x5C, 0x45, 0x99, 0x9E, 0x24 },
asf_read_unknown, 1 },
929 {
"Bandwidth Sharing Object", { 0xA6, 0x96, 0x09, 0xE6, 0x51, 0x7B, 0x11, 0xD2, 0xB6, 0xAF, 0x00, 0xC0, 0x4F, 0xD9, 0x08, 0xE9 },
asf_read_unknown, 1 },
930 {
"Metadata", { 0xC5, 0xF8, 0xCB, 0xEA, 0x5B, 0xAF, 0x48, 0x77, 0x84, 0x67, 0xAA, 0x8C, 0x44, 0xFA, 0x4C, 0xCA },
asf_read_metadata_obj, 1 },
931 {
"Metadata Library", { 0x44, 0x23, 0x1C, 0x94, 0x94, 0x98, 0x49, 0xD1, 0xA1, 0x41, 0x1D, 0x13, 0x4E, 0x45, 0x70, 0x54 },
asf_read_metadata_obj, 1 },
932 {
"Audio Spread", { 0xBF, 0xC3, 0xCD, 0x50, 0x61, 0x8F, 0x11, 0xCF, 0x8B, 0xB2, 0x00, 0xAA, 0x00, 0xB4, 0xE2, 0x20 },
asf_read_unknown, 1 },
933 {
"Index Parameters", { 0xD6, 0xE2, 0x29, 0xDF, 0x35, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE },
asf_read_unknown, 1 },
934 {
"Content Encryption System Windows Media DRM Network Devices",
935 { 0x7A, 0x07, 0x9B, 0xB6, 0xDA, 0XA4, 0x4e, 0x12, 0xA5, 0xCA, 0x91, 0xD3, 0x8D, 0xC1, 0x1A, 0x8D },
asf_read_unknown, 1 },
936 {
"Mutex Language", { 0xD6, 0xE2, 0x2A, 0x00, 0x25, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE },
asf_read_unknown, 1 },
937 {
"Mutex Bitrate", { 0xD6, 0xE2, 0x2A, 0x01, 0x25, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE },
asf_read_unknown, 1 },
938 {
"Mutex Unknown", { 0xD6, 0xE2, 0x2A, 0x02, 0x25, 0xDA, 0x11, 0xD1, 0x90, 0x34, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xBE },
asf_read_unknown, 1 },
939 {
"Bandwidth Sharing Exclusive", { 0xAF, 0x60, 0x60, 0xAA, 0x51, 0x97, 0x11, 0xD2, 0xB6, 0xAF, 0x00, 0xC0, 0x4F, 0xD9, 0x08, 0xE9 },
asf_read_unknown, 1 },
940 {
"Bandwidth Sharing Partial", { 0xAF, 0x60, 0x60, 0xAB, 0x51, 0x97, 0x11, 0xD2, 0xB6, 0xAF, 0x00, 0xC0, 0x4F, 0xD9, 0x08, 0xE9 },
asf_read_unknown, 1 },
941 {
"Payload Extension System Timecode", { 0x39, 0x95, 0x95, 0xEC, 0x86, 0x67, 0x4E, 0x2D, 0x8F, 0xDB, 0x98, 0x81, 0x4C, 0xE7, 0x6C, 0x1E },
asf_read_unknown, 1 },
942 {
"Payload Extension System File Name", { 0xE1, 0x65, 0xEC, 0x0E, 0x19, 0xED, 0x45, 0xD7, 0xB4, 0xA7, 0x25, 0xCB, 0xD1, 0xE2, 0x8E, 0x9B },
asf_read_unknown, 1 },
943 {
"Payload Extension System Content Type", { 0xD5, 0x90, 0xDC, 0x20, 0x07, 0xBC, 0x43, 0x6C, 0x9C, 0xF7, 0xF3, 0xBB, 0xFB, 0xF1, 0xA4, 0xDC },
asf_read_unknown, 1 },
944 {
"Payload Extension System Pixel Aspect Ratio", { 0x1, 0x1E, 0xE5, 0x54, 0xF9, 0xEA, 0x4B, 0xC8, 0x82, 0x1A, 0x37, 0x6B, 0x74, 0xE4, 0xC4, 0xB8 },
asf_read_unknown, 1 },
945 {
"Payload Extension System Sample Duration", { 0xC6, 0xBD, 0x94, 0x50, 0x86, 0x7F, 0x49, 0x07, 0x83, 0xA3, 0xC7, 0x79, 0x21, 0xB7, 0x33, 0xAD },
asf_read_unknown, 1 },
946 {
"Payload Extension System Encryption Sample ID", { 0x66, 0x98, 0xB8, 0x4E, 0x0A, 0xFA, 0x43, 0x30, 0xAE, 0xB2, 0x1C, 0x0A, 0x98, 0xD7, 0xA4, 0x4D },
asf_read_unknown, 1 },
947 {
"Payload Extension System Degradable JPEG", { 0x00, 0xE1, 0xAF, 0x06, 0x7B, 0xEC, 0x11, 0xD1, 0xA5, 0x82, 0x00, 0xC0, 0x4F, 0xC2, 0x9C, 0xFB },
asf_read_unknown, 1 },
950 #define READ_LEN(flag, name, len) \
952 if ((flag) == name ## IS_BYTE) \
954 else if ((flag) == name ## IS_WORD) \
955 len = avio_rl16(pb); \
956 else if ((flag) == name ## IS_DWORD) \
957 len = avio_rl32(pb); \
1007 "Position %"PRId64
" wrong, should be %"PRId64
"\n",
1062 asf->
state = READ_MULTI_SUB;
1073 "Error: invalid data packet size, pay_len %"PRIu16
", "
1074 "asf->packet_size %"PRIu32
", offset %"PRId64
".\n",
1081 "Error: invalid buffer size, pay_len %d, data size left %d.\n",
1090 if (
s->key &&
s->keylen == 20)
1130 "Error: invalid data packet size, offset %"PRId64
".\n",
1143 if (
s->key &&
s->keylen == 20)
1160 uint32_t off_len, media_len;
1186 if (stream_num >> 7)
1189 ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_, media_len);
1191 ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_, off_len);
1193 ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_, asf->
rep_data_len);
1205 asf->
state = READ_SINGLE;
1238 unsigned char error_flags, len_flags, pay_flags;
1249 len_flags = error_flags;
1254 ASF_PPI_FLAG_SEQUENCE_FIELD_, seq);
1256 ASF_PPI_FLAG_PADDING_LENGTH_FIELD_, asf->
pad_len );
1271 unsigned char *p = asf_pkt->
avpkt->
data;
1274 int nchunks = pkt_len / chunk_len;
1288 for (l = 0; l < pkt_len; l++) {
1292 for (j = 0; j < asf_st->
span; j++) {
1296 p + (j * nchunks + l) * chunk_len,
1301 p += asf_st->
span * pkt_len;
1323 if (asf->
state == PARSE_PACKET_HEADER) {
1328 asf->
state = READ_SINGLE;
1330 asf->
state = READ_MULTI;
1334 asf->
state = PARSE_PACKET_HEADER;
1340 switch (asf->
state) {
1343 asf->
state = PARSE_PACKET_HEADER;
1345 case READ_MULTI_SUB:
1347 asf->
state = PARSE_PACKET_HEADER;
1355 asf->
state = READ_MULTI;
1359 asf->
state = PARSE_PACKET_HEADER;
1419 asf->
state = PARSE_PACKET_HEADER;
1451 int64_t *
pos, int64_t pos_limit)
1469 pkt_offset = pkt_pos;
1474 int i,
ret, st_found;
1495 if (stream_index == st->
index) {
1513 int64_t timestamp,
int flags)
1516 AVStream *
const st =
s->streams[stream_index];
1543 if (!(
ret = memcmp(guid,
g->guid,
sizeof(
g->guid))))
1570 if ((
ret =
g->read_object(
s,
g)) < 0)
1575 g2.
name =
"Unknown";
1621 if ((
ret =
g->read_object(
s,
g)) < 0)