annotate asf-enc.c @ 1533:15482c2cd208 libavformat

cosmetics: reindent after last commit
author aurel
date Mon, 20 Nov 2006 00:33:47 +0000
parents 3b00fb8ef8e4
children 65b7b3ff4ed7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
1415
3b00fb8ef8e4 replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents: 1358
diff changeset
2 * Adaptive stream format muxer
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1345
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1345
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1345
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1345
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1345
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1345
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include "avformat.h"
1172
6a5e58d2114b move common stuff from avienc.c and wav.c to new file riff.c
mru
parents: 1169
diff changeset
22 #include "riff.h"
372
2e12cd1b68ed split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 370
diff changeset
23 #include "asf.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
25 #undef NDEBUG
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
26 #include <assert.h>
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
27
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
28
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
29 #define ASF_INDEXED_INTERVAL 10000000
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
30 #define ASF_INDEX_BLOCK 600
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
31
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
32 #define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE 0x2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
33 #define ASF_PACKET_ERROR_CORRECTION_FLAGS (\
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
34 ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT | \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
35 ASF_PACKET_ERROR_CORRECTION_DATA_SIZE\
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
36 )
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
37
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
38 #if (ASF_PACKET_ERROR_CORRECTION_FLAGS != 0)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
39 # define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 1
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
40 #else
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
41 # define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
42 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
43
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
44 #define ASF_PPI_PROPERTY_FLAGS (\
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
45 ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE | \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
46 ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD | \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
47 ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE | \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
48 ASF_PL_FLAG_STREAM_NUMBER_LENGTH_FIELD_IS_BYTE \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
49 )
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
50
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
51 #define ASF_PPI_LENGTH_TYPE_FLAGS 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
52
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
53 #define ASF_PAYLOAD_FLAGS ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
54
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
55 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
56 # define ASF_PPI_SEQUENCE_FIELD_SIZE 1
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
57 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
58 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
59 # define ASF_PPI_SEQUENCE_FIELD_SIZE 2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
60 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
61 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
62 # define ASF_PPI_SEQUENCE_FIELD_SIZE 4
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
63 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
64 #ifndef ASF_PPI_SEQUENCE_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
65 # define ASF_PPI_SEQUENCE_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
66 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
67
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
68
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
69 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
70 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 1
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
71 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
72 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
73 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
74 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
75 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
76 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 4
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
77 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
78 #ifndef ASF_PPI_PACKET_LENGTH_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
79 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
80 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
81
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
82 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
83 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 1
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
84 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
85 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
86 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
87 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
88 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
89 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 4
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
90 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
91 #ifndef ASF_PPI_PADDING_LENGTH_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
92 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
93 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
94
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
95 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
96 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 1
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
97 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
98 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
99 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
100 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
101 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
102 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 4
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
103 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
104 #ifndef ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
105 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
106 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
107
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
108 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
109 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 1
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
110 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
111 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
112 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
113 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
114 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
115 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 4
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
116 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
117 #ifndef ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
118 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
119 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
120
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
121 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
122 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 1
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
123 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
124 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
125 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
126 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
127 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
128 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 4
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
129 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
130 #ifndef ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
131 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
132 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
133
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
134 #if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_BYTE == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
135 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 1
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
136 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
137 #if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
138 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
139 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
140 #ifndef ASF_PAYLOAD_LENGTH_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
141 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
142 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
143
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
144 #define PACKET_HEADER_MIN_SIZE (\
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
145 ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
146 ASF_PACKET_ERROR_CORRECTION_DATA_SIZE + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
147 1 + /*Length Type Flags*/ \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
148 1 + /*Property Flags*/ \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
149 ASF_PPI_PACKET_LENGTH_FIELD_SIZE + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
150 ASF_PPI_SEQUENCE_FIELD_SIZE + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
151 ASF_PPI_PADDING_LENGTH_FIELD_SIZE + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
152 4 + /*Send Time Field*/ \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
153 2 /*Duration Field*/ \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
154 )
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
155
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
156
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
157 // Replicated Data shall be at least 8 bytes long.
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
158 #define ASF_PAYLOAD_REPLICATED_DATA_LENGTH 0x08
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
159
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
160 #define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD (\
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
161 1 + /*Stream Number*/ \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
162 ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
163 ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
164 ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
165 ASF_PAYLOAD_REPLICATED_DATA_LENGTH \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
166 )
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
167
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
168 #define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS (\
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
169 1 + /*Stream Number*/ \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
170 ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
171 ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
172 ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
173 ASF_PAYLOAD_REPLICATED_DATA_LENGTH + \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
174 ASF_PAYLOAD_LENGTH_FIELD_SIZE \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
175 )
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
176
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
177 #define SINGLE_PAYLOAD_DATA_LENGTH (\
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
178 PACKET_SIZE - \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
179 PACKET_HEADER_MIN_SIZE - \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
180 PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
181 )
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
182
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
183 #define MULTI_PAYLOAD_CONSTANT (\
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
184 PACKET_SIZE - \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
185 PACKET_HEADER_MIN_SIZE - \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
186 1 - /*Payload Flags*/ \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
187 2*PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
188 )
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
189
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
190 static int preroll_time = 2000;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
191
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
192 static const uint8_t error_spread_ADPCM_G726[] = { 0x01, 0x90, 0x01, 0x90, 0x01, 0x01, 0x00, 0x00 };
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
193
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 static void put_guid(ByteIOContext *s, const GUID *g)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 put_le32(s, g->v1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 put_le16(s, g->v2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 put_le16(s, g->v3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 put_byte(s, g->v4[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 static void put_str16(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 put_le16(s,strlen(tag) + 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 for(;;) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
211 c = (uint8_t)*tag++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 put_le16(s, c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 static void put_str16_nolen(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 for(;;) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
223 c = (uint8_t)*tag++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 put_le16(s, c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
230 static int64_t put_header(ByteIOContext *pb, const GUID *g)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
232 int64_t pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 put_guid(pb, g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 put_le64(pb, 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 return pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 /* update header size */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
241 static void end_header(ByteIOContext *pb, int64_t pos)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
243 int64_t pos1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 pos1 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 url_fseek(pb, pos + 16, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 put_le64(pb, pos1 - pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 url_fseek(pb, pos1, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 /* write an asf chunk (only used in streaming case) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 int length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 length = payload_length + 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 put_le16(pb, type);
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
260 put_le16(pb, length); //size
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
261 put_le32(pb, asf->seqno);//sequence number
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 put_le16(pb, flags); /* unknown bytes */
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
263 put_le16(pb, length); //size_confirm
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 asf->seqno++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 /* convert from unix to windows time */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
268 static int64_t unix_to_file_time(int ti)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
270 int64_t t;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
272 t = ti * int64_t_C(10000000);
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
273 t += int64_t_C(116444736000000000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 return t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 /* write the header (used two times if non streamed) */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
278 static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 int has_title;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 AVCodecContext *enc;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
285 int64_t header_offset, cur_pos, hpos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 int bit_rate;
1345
0a74030d9dd7 Fix wrong ASF duration of generated files
gpoirier
parents: 1172
diff changeset
287 int64_t duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288
1345
0a74030d9dd7 Fix wrong ASF duration of generated files
gpoirier
parents: 1172
diff changeset
289 duration = asf->duration + preroll_time * 10000;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 bit_rate = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 for(n=0;n<s->nb_streams;n++) {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
294 enc = s->streams[n]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295
462
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 373
diff changeset
296 av_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 373
diff changeset
297
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 bit_rate += enc->bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 put_guid(pb, &asf_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 put_le64(pb, -1); /* header length, will be patched after */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 put_byte(pb, 2); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 /* file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 header_offset = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313 hpos = put_header(pb, &file_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 put_guid(pb, &my_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 put_le64(pb, file_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 file_time = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 put_le64(pb, unix_to_file_time(file_time));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 put_le64(pb, asf->nb_packets); /* number of packets */
1345
0a74030d9dd7 Fix wrong ASF duration of generated files
gpoirier
parents: 1172
diff changeset
319 put_le64(pb, duration); /* end time stamp (in 100ns units) */
0a74030d9dd7 Fix wrong ASF duration of generated files
gpoirier
parents: 1172
diff changeset
320 put_le64(pb, duration); /* duration (in 100ns units) */
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
321 put_le32(pb, preroll_time); /* start time stamp */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 put_le32(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 put_le32(pb, asf->packet_size); /* packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 put_le32(pb, asf->packet_size); /* packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 put_le32(pb, bit_rate); /* Nominal data rate in bps */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 /* unknown headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 hpos = put_header(pb, &head1_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 put_guid(pb, &head2_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 put_le32(pb, 6);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 /* title and other infos */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 if (has_title) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 hpos = put_header(pb, &comment_header);
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
339 if ( s->title[0] ) { put_le16(pb, 2 * (strlen(s->title ) + 1)); } else { put_le16(pb, 0); }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
340 if ( s->author[0] ) { put_le16(pb, 2 * (strlen(s->author ) + 1)); } else { put_le16(pb, 0); }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
341 if ( s->copyright[0] ) { put_le16(pb, 2 * (strlen(s->copyright) + 1)); } else { put_le16(pb, 0); }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
342 if ( s->comment[0] ) { put_le16(pb, 2 * (strlen(s->comment ) + 1)); } else { put_le16(pb, 0); }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 put_le16(pb, 0);
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
344 if ( s->title[0] ) put_str16_nolen(pb, s->title);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
345 if ( s->author[0] ) put_str16_nolen(pb, s->author);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
346 if ( s->copyright[0] ) put_str16_nolen(pb, s->copyright);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
347 if ( s->comment[0] ) put_str16_nolen(pb, s->comment);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 /* stream headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 for(n=0;n<s->nb_streams;n++) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
353 int64_t es_pos;
1123
6992dd78ff68 Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents: 896
diff changeset
354 const uint8_t *er_spr = NULL;
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
355 int er_spr_len = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 // ASFStream *stream = &asf->streams[n];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
358 enc = s->streams[n]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 asf->streams[n].num = n + 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 asf->streams[n].seq = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
362
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
363 if (enc->codec_type == CODEC_TYPE_AUDIO) {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
364 if (enc->codec_id == CODEC_ID_ADPCM_G726) {
1123
6992dd78ff68 Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents: 896
diff changeset
365 er_spr = error_spread_ADPCM_G726;
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
366 er_spr_len = sizeof(error_spread_ADPCM_G726);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
367 }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
368 }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
369
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 switch(enc->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 wav_extra_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 extra_size = 18 + wav_extra_size;
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
374 extra_size2 = er_spr_len;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 case CODEC_TYPE_VIDEO:
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
378 wav_extra_size = enc->extradata_size;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
379 extra_size = 0x33 + wav_extra_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 extra_size2 = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384 hpos = put_header(pb, &stream_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 put_guid(pb, &audio_stream);
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
387 if ((er_spr != NULL) && (er_spr_len != 0)) {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
388 put_guid(pb, &audio_conceal_spread);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
389 } else {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
390 put_guid(pb, &video_conceal_none);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
391 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 put_guid(pb, &video_stream);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 put_guid(pb, &video_conceal_none);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 put_le64(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 es_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 put_le32(pb, extra_size); /* wav header len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 put_le32(pb, extra_size2); /* additional data len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 put_le16(pb, n + 1); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 put_le32(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 /* WAVEFORMATEX header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 int wavsize = put_wav_header(pb, enc);
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
406 if ((enc->codec_id != CODEC_ID_MP3) && (enc->codec_id != CODEC_ID_MP2) && (enc->codec_id != CODEC_ID_ADPCM_IMA_WAV) && (enc->extradata_size==0)) {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
407 wavsize += 2;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
408 put_le16(pb, 0);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
409 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 if (wavsize < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 if (wavsize != extra_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 cur_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 url_fseek(pb, es_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 put_le32(pb, wavsize); /* wav header len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 url_fseek(pb, cur_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 }
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
419 /* ERROR Correction */
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
420 if ((er_spr != NULL) && (er_spr_len != 0))
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
421 put_buffer(pb, er_spr, er_spr_len);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 put_le32(pb, enc->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 put_le32(pb, enc->height);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 put_byte(pb, 2); /* ??? */
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
426 put_le16(pb, 40 + enc->extradata_size); /* size */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 /* BITMAPINFOHEADER header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 put_bmp_header(pb, enc, codec_bmp_tags, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434 /* media comments */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 hpos = put_header(pb, &codec_comment_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 put_guid(pb, &codec_comment1_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 put_le32(pb, s->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 AVCodec *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
442 enc = s->streams[n]->codec;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 p = avcodec_find_encoder(enc->codec_id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 put_le16(pb, asf->streams[n].num);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 put_str16(pb, p ? p->name : enc->codec_name);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 put_le16(pb, 0); /* no parameters */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
448
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
449
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 /* id */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 put_le16(pb, 2);
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
453 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
454 enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
455 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
456 return -1;
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
457 put_le16(pb, enc->codec_tag);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 put_le16(pb, 4);
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
460 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
461 enc->codec_tag = codec_get_tag(codec_bmp_tags, enc->codec_id);
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
462 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
463 return -1;
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
464 put_le32(pb, enc->codec_tag);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 /* patch the header size fields */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 cur_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 header_size = cur_pos - header_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 header_size += 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 header_size -= 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 header_size += 24 + 6;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484 url_fseek(pb, header_offset - 14, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 put_le64(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486 url_fseek(pb, cur_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 /* movie chunk, followed by packets of packet_size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 asf->data_offset = cur_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 put_guid(pb, &data_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 put_le64(pb, data_chunk_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 put_guid(pb, &my_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 put_le64(pb, asf->nb_packets); /* nb packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 static int asf_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 asf->packet_size = PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 asf->nb_packets = 0;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
505
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
506 asf->last_indexed_pts = 0;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
507 asf->index_ptr = (ASFIndex*)av_malloc( sizeof(ASFIndex) * ASF_INDEX_BLOCK );
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
508 asf->nb_index_memory_alloc = ASF_INDEX_BLOCK;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
509 asf->nb_index_count = 0;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
510 asf->maximum_packet = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 if (asf_write_header1(s, 0, 50) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 //av_free(asf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
519 asf->packet_nb_payloads = 0;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
520 asf->prev_packet_sent_time = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 static int asf_write_stream_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 asf->is_streamed = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 return asf_write_header(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
538 static int put_payload_parsing_info(
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
539 AVFormatContext *s,
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
540 unsigned int sendtime,
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
541 unsigned int duration,
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
542 int nb_payloads,
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
543 int padsize
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
544 )
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547 ByteIOContext *pb = &s->pb;
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
548 int ppi_size, i;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
549 unsigned char *start_ppi_ptr = pb->buf_ptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
551 int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
552
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
553 put_byte(pb, ASF_PACKET_ERROR_CORRECTION_FLAGS);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
554 for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++){
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
555 put_byte(pb, 0x0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
558 if (asf->multi_payloads_present)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
559 iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 if (padsize > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 if (padsize < 256)
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
563 iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564 else
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
565 iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 }
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
567 put_byte(pb, iLengthTypeFlags);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
568
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
569 put_byte(pb, ASF_PPI_PROPERTY_FLAGS);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
570
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
571 if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572 put_le16(pb, padsize - 2);
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
573 if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 put_byte(pb, padsize - 1);
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
575
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
576 put_le32(pb, sendtime);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 put_le16(pb, duration);
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
578 if (asf->multi_payloads_present)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
579 put_byte(pb, nb_payloads | ASF_PAYLOAD_FLAGS);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
581 ppi_size = pb->buf_ptr - start_ppi_ptr;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
582
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
583 return ppi_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 static void flush_packet(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 ASFContext *asf = s->priv_data;
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
589 int packet_hdr_size, packet_filled_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
591 if (asf->is_streamed) {
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
592 put_chunk(s, 0x4424, asf->packet_size, 0);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
593 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
595 packet_hdr_size = put_payload_parsing_info(
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
596 s,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
597 asf->packet_timestamp_start,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
598 asf->packet_timestamp_end - asf->packet_timestamp_start,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
599 asf->packet_nb_payloads,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
600 asf->packet_size_left
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
601 );
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
603 packet_filled_size = PACKET_SIZE - packet_hdr_size - asf->packet_size_left;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
604 memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
605
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
606 put_buffer(&s->pb, asf->packet_buf, asf->packet_size - packet_hdr_size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 asf->nb_packets++;
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
610 asf->packet_nb_payloads = 0;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
611 asf->prev_packet_sent_time = asf->packet_timestamp_start;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
618 static void put_payload_header(
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
619 AVFormatContext *s,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
620 ASFStream *stream,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
621 int presentation_time,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
622 int m_obj_size,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
623 int m_obj_offset,
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
624 int payload_len,
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
625 int flags
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
626 )
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629 ByteIOContext *pb = &asf->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 int val;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
631
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632 val = stream->num;
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
633 if (flags & PKT_FLAG_KEY)
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
634 val |= ASF_PL_FLAG_KEY_FRAME;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 put_byte(pb, val);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
636
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
637 put_byte(pb, stream->seq); //Media object number
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
638 put_le32(pb, m_obj_offset); //Offset Into Media Object
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
639
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
640 // Replicated Data shall be at least 8 bytes long.
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
641 // The first 4 bytes of data shall contain the
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
642 // Size of the Media Object that the payload belongs to.
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
643 // The next 4 bytes of data shall contain the
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
644 // Presentation Time for the media object that the payload belongs to.
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
645 put_byte(pb, ASF_PAYLOAD_REPLICATED_DATA_LENGTH);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
646
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
647 put_le32(pb, m_obj_size); //Replicated Data - Media Object Size
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
648 put_le32(pb, presentation_time);//Replicated Data - Presentation Time
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
649
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
650 if (asf->multi_payloads_present){
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
651 put_le16(pb, payload_len); //payload length
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
652 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
653 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
655 static void put_frame(
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
656 AVFormatContext *s,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
657 ASFStream *stream,
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
658 int timestamp,
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
659 const uint8_t *buf,
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
660 int m_obj_size,
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
661 int flags
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
662 )
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664 ASFContext *asf = s->priv_data;
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
665 int m_obj_offset, payload_len, frag_len1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
667 m_obj_offset = 0;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
668 while (m_obj_offset < m_obj_size) {
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
669 payload_len = m_obj_size - m_obj_offset;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
670 if (asf->packet_timestamp_start == -1) {
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
671 asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
672
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
673 if (asf->multi_payloads_present){
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
674 asf->packet_size_left = PACKET_SIZE; //For debug
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
675 asf->packet_size_left = PACKET_SIZE - PACKET_HEADER_MIN_SIZE - 1;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
676 frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
677 }
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
678 else {
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
679 asf->packet_size_left = PACKET_SIZE - PACKET_HEADER_MIN_SIZE;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
680 frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
681 }
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
682 if (asf->prev_packet_sent_time > timestamp)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
683 asf->packet_timestamp_start = asf->prev_packet_sent_time;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
684 else
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
685 asf->packet_timestamp_start = timestamp;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
686 }
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
687 else {
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
688 // multi payloads
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
689 frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
690
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
691 if (asf->prev_packet_sent_time > timestamp)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
692 asf->packet_timestamp_start = asf->prev_packet_sent_time;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
693 else if (asf->packet_timestamp_start >= timestamp)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
694 asf->packet_timestamp_start = timestamp;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
695 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
696 if (frag_len1 > 0) {
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
697 if (payload_len > frag_len1)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
698 payload_len = frag_len1;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
699 else if (payload_len == (frag_len1 - 1))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
700 payload_len = frag_len1 - 2; //additional byte need to put padding length
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
701
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
702 put_payload_header(s, stream, timestamp+preroll_time, m_obj_size, m_obj_offset, payload_len, flags);
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
703 put_buffer(&asf->pb, buf, payload_len);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
704
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
705 if (asf->multi_payloads_present)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
706 asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
707 else
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
708 asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709 asf->packet_timestamp_end = timestamp;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
710
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
711 asf->packet_nb_payloads++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
712 } else {
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
713 payload_len = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714 }
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
715 m_obj_offset += payload_len;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
716 buf += payload_len;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
717
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
718 if (!asf->multi_payloads_present)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
719 flush_packet(s);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
720 else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + 1))
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
723 stream->seq++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
724 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
725
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
726 static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 ASFStream *stream;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
730 int64_t duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
731 AVCodecContext *codec;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
732 int64_t packet_st,pts;
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
733 int start_sec,i;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
734
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 743
diff changeset
735 codec = s->streams[pkt->stream_index]->codec;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
736 stream = &asf->streams[pkt->stream_index];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
737
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
738 //XXX /FIXME use duration from AVPacket (quick hack by)
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
739 pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
740 if (pts == AV_NOPTS_VALUE) {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
741 if (codec->codec_type == CODEC_TYPE_AUDIO) {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
742 duration = (codec->frame_number * (int64_t)codec->frame_size * int64_t_C(10000000)) /
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
743 codec->sample_rate;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
744 } else {
743
af4e24d6310c switch to native time bases
michael
parents: 716
diff changeset
745 duration = av_rescale(codec->frame_number * (int64_t)codec->time_base.num, 10000000, codec->time_base.den);
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
746 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
747 } else {
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
748 duration = pts * 10000;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
749 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
750 if (duration > asf->duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
751 asf->duration = duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
752
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
753 packet_st = asf->nb_packets;
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
754 put_frame(s, stream, pkt->pts, pkt->data, pkt->size, pkt->flags);
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
755
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
756 /* check index */
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
757 if ((!asf->is_streamed) && (codec->codec_type == CODEC_TYPE_VIDEO) && (pkt->flags & PKT_FLAG_KEY)) {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
758 start_sec = (int)(duration / int64_t_C(10000000));
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
759 if (start_sec != (int)(asf->last_indexed_pts / int64_t_C(10000000))) {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
760 for(i=asf->nb_index_count;i<start_sec;i++) {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
761 if (i>=asf->nb_index_memory_alloc) {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
762 asf->nb_index_memory_alloc += ASF_INDEX_BLOCK;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
763 asf->index_ptr = (ASFIndex*)av_realloc( asf->index_ptr, sizeof(ASFIndex) * asf->nb_index_memory_alloc );
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
764 }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
765 // store
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
766 asf->index_ptr[i].packet_number = (uint32_t)packet_st;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
767 asf->index_ptr[i].packet_count = (uint16_t)(asf->nb_packets-packet_st);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
768 if (asf->maximum_packet < (uint16_t)(asf->nb_packets-packet_st))
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
769 asf->maximum_packet = (uint16_t)(asf->nb_packets-packet_st);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
770 }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
771 asf->nb_index_count = start_sec;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
772 asf->last_indexed_pts = duration;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
773 }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
774 }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
775 return 0;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
776 }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
777
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
778 //
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
779 static int asf_write_index(AVFormatContext *s, ASFIndex *index, uint16_t max, uint32_t count)
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
780 {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
781 ByteIOContext *pb = &s->pb;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
782 int i;
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
783
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
784 put_guid(pb, &simple_index_header);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
785 put_le64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2)*count);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
786 put_guid(pb, &my_guid);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
787 put_le64(pb, ASF_INDEXED_INTERVAL);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
788 put_le32(pb, max);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
789 put_le32(pb, count);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
790 for(i=0; i<count; i++) {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
791 put_le32(pb, index[i].packet_number);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
792 put_le16(pb, index[i].packet_count);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
793 }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
794
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
795 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
796 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
797
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
798 static int asf_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
800 ASFContext *asf = s->priv_data;
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
801 int64_t file_size,data_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
802
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
803 /* flush the current packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
804 if (asf->pb.buf_ptr > asf->pb.buffer)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
805 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
806
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
807 /* write index */
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
808 data_size = url_ftell(&s->pb);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
809 if ((!asf->is_streamed) && (asf->nb_index_count != 0)) {
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
810 asf_write_index(s, asf->index_ptr, asf->maximum_packet, asf->nb_index_count);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
811 }
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
812 put_flush_packet(&s->pb);
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
813
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
814 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
815 put_chunk(s, 0x4524, 0, 0); /* end of stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
816 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
817 /* rewrite an updated header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
818 file_size = url_ftell(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
819 url_fseek(&s->pb, 0, SEEK_SET);
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
820 asf_write_header1(s, file_size, data_size - asf->data_offset);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
821 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
822
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
823 put_flush_packet(&s->pb);
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
824 av_free(asf->index_ptr);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
825 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
826 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
827
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
828 #ifdef CONFIG_ASF_MUXER
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1123
diff changeset
829 AVOutputFormat asf_muxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
830 "asf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
831 "asf format",
14
b167760cd0aa mimetype fixes patch by (Ryutaroh Matsumoto <ryutaroh at it dot ss dot titech dot ac dot jp>)
michaelni
parents: 7
diff changeset
832 "video/x-ms-asf",
672
michael
parents: 668
diff changeset
833 "asf,wmv,wma",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
834 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
835 #ifdef CONFIG_MP3LAME
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
836 CODEC_ID_MP3,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
837 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
838 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
840 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841 asf_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
842 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
843 asf_write_trailer,
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
844 .flags = AVFMT_GLOBALHEADER,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
845 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
846 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
847
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
848 #ifdef CONFIG_ASF_STREAM_MUXER
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1123
diff changeset
849 AVOutputFormat asf_stream_muxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
850 "asf_stream",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
851 "asf format",
14
b167760cd0aa mimetype fixes patch by (Ryutaroh Matsumoto <ryutaroh at it dot ss dot titech dot ac dot jp>)
michaelni
parents: 7
diff changeset
852 "video/x-ms-asf",
672
michael
parents: 668
diff changeset
853 "asf,wmv,wma",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
854 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
855 #ifdef CONFIG_MP3LAME
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
856 CODEC_ID_MP3,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
857 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
858 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
859 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
860 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
861 asf_write_stream_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
862 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
863 asf_write_trailer,
716
55081ada3aad 31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents: 672
diff changeset
864 .flags = AVFMT_GLOBALHEADER,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
865 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
866 #endif //CONFIG_ASF_STREAM_MUXER