Mercurial > libavformat.hg
annotate asf-enc.c @ 716:55081ada3aad libavformat
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
author | michael |
---|---|
date | Wed, 23 Mar 2005 13:30:27 +0000 |
parents | e23ef5378293 |
children | af4e24d6310c |
rev | line source |
---|---|
0 | 1 /* |
372
2e12cd1b68ed
split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
370
diff
changeset
|
2 * Adaptive stream format encoder |
0 | 3 * Copyright (c) 2000, 2001 Fabrice Bellard. |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 #include "avformat.h" | |
20 #include "avi.h" | |
372
2e12cd1b68ed
split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
370
diff
changeset
|
21 #include "asf.h" |
0 | 22 |
348 | 23 #undef NDEBUG |
24 #include <assert.h> | |
25 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
26 #ifdef CONFIG_ENCODERS |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
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 |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
29 #define ASF_INDEXED_INTERVAL 10000000 |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
30 #define ASF_INDEX_BLOCK 600 |
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 (\ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
34 ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT | \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
35 ASF_PACKET_ERROR_CORRECTION_DATA_SIZE\ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
36 ) |
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 (\ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
45 ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE | \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
46 ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD | \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
47 ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE | \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
48 ASF_PL_FLAG_STREAM_NUMBER_LENGTH_FIELD_IS_BYTE \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
49 ) |
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 (\ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
145 ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
146 ASF_PACKET_ERROR_CORRECTION_DATA_SIZE + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
147 1 + /*Length Type Flags*/ \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
148 1 + /*Property Flags*/ \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
149 ASF_PPI_PACKET_LENGTH_FIELD_SIZE + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
150 ASF_PPI_SEQUENCE_FIELD_SIZE + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
151 ASF_PPI_PADDING_LENGTH_FIELD_SIZE + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
152 4 + /*Send Time Field*/ \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
153 2 /*Duration Field*/ \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
154 ) |
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 (\ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
161 1 + /*Stream Number*/ \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
162 ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
163 ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
164 ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
165 ASF_PAYLOAD_REPLICATED_DATA_LENGTH \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
166 ) |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
167 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
168 #define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS (\ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
169 1 + /*Stream Number*/ \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
170 ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
171 ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
172 ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
173 ASF_PAYLOAD_REPLICATED_DATA_LENGTH + \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
174 ASF_PAYLOAD_LENGTH_FIELD_SIZE \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
175 ) |
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 (\ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
178 PACKET_SIZE - \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
179 PACKET_HEADER_MIN_SIZE - \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
180 PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
181 ) |
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 (\ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
184 PACKET_SIZE - \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
185 PACKET_HEADER_MIN_SIZE - \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
186 1 - /*Payload Flags*/ \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
187 2*PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
188 ) |
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 | 194 static void put_guid(ByteIOContext *s, const GUID *g) |
195 { | |
196 int i; | |
197 | |
198 put_le32(s, g->v1); | |
199 put_le16(s, g->v2); | |
200 put_le16(s, g->v3); | |
201 for(i=0;i<8;i++) | |
202 put_byte(s, g->v4[i]); | |
203 } | |
204 | |
205 static void put_str16(ByteIOContext *s, const char *tag) | |
206 { | |
207 int c; | |
208 | |
209 put_le16(s,strlen(tag) + 1); | |
210 for(;;) { | |
65 | 211 c = (uint8_t)*tag++; |
0 | 212 put_le16(s, c); |
213 if (c == '\0') | |
214 break; | |
215 } | |
216 } | |
217 | |
218 static void put_str16_nolen(ByteIOContext *s, const char *tag) | |
219 { | |
220 int c; | |
221 | |
222 for(;;) { | |
65 | 223 c = (uint8_t)*tag++; |
0 | 224 put_le16(s, c); |
225 if (c == '\0') | |
226 break; | |
227 } | |
228 } | |
229 | |
65 | 230 static int64_t put_header(ByteIOContext *pb, const GUID *g) |
0 | 231 { |
65 | 232 int64_t pos; |
0 | 233 |
234 pos = url_ftell(pb); | |
235 put_guid(pb, g); | |
236 put_le64(pb, 24); | |
237 return pos; | |
238 } | |
239 | |
240 /* update header size */ | |
65 | 241 static void end_header(ByteIOContext *pb, int64_t pos) |
0 | 242 { |
65 | 243 int64_t pos1; |
0 | 244 |
245 pos1 = url_ftell(pb); | |
246 url_fseek(pb, pos + 16, SEEK_SET); | |
247 put_le64(pb, pos1 - pos); | |
248 url_fseek(pb, pos1, SEEK_SET); | |
249 } | |
250 | |
251 /* write an asf chunk (only used in streaming case) */ | |
252 static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags) | |
253 { | |
254 ASFContext *asf = s->priv_data; | |
255 ByteIOContext *pb = &s->pb; | |
256 int length; | |
257 | |
258 length = payload_length + 8; | |
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 | 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 | 264 asf->seqno++; |
265 } | |
266 | |
267 /* convert from unix to windows time */ | |
65 | 268 static int64_t unix_to_file_time(int ti) |
0 | 269 { |
65 | 270 int64_t t; |
0 | 271 |
65 | 272 t = ti * int64_t_C(10000000); |
273 t += int64_t_C(116444736000000000); | |
0 | 274 return t; |
275 } | |
276 | |
277 /* write the header (used two times if non streamed) */ | |
65 | 278 static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size) |
0 | 279 { |
280 ASFContext *asf = s->priv_data; | |
281 ByteIOContext *pb = &s->pb; | |
282 int header_size, n, extra_size, extra_size2, wav_extra_size, file_time; | |
283 int has_title; | |
284 AVCodecContext *enc; | |
65 | 285 int64_t header_offset, cur_pos, hpos; |
0 | 286 int bit_rate; |
287 | |
288 has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]); | |
289 | |
290 bit_rate = 0; | |
291 for(n=0;n<s->nb_streams;n++) { | |
292 enc = &s->streams[n]->codec; | |
293 | |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
373
diff
changeset
|
294 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
|
295 |
0 | 296 bit_rate += enc->bit_rate; |
297 } | |
298 | |
299 if (asf->is_streamed) { | |
300 put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */ | |
301 } | |
302 | |
303 put_guid(pb, &asf_header); | |
304 put_le64(pb, -1); /* header length, will be patched after */ | |
305 put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */ | |
306 put_byte(pb, 1); /* ??? */ | |
307 put_byte(pb, 2); /* ??? */ | |
308 | |
309 /* file header */ | |
310 header_offset = url_ftell(pb); | |
311 hpos = put_header(pb, &file_header); | |
312 put_guid(pb, &my_guid); | |
313 put_le64(pb, file_size); | |
314 file_time = 0; | |
315 put_le64(pb, unix_to_file_time(file_time)); | |
316 put_le64(pb, asf->nb_packets); /* number of packets */ | |
317 put_le64(pb, asf->duration); /* end time stamp (in 100ns units) */ | |
318 put_le64(pb, asf->duration); /* duration (in 100ns units) */ | |
468 | 319 put_le32(pb, preroll_time); /* start time stamp */ |
0 | 320 put_le32(pb, 0); /* ??? */ |
321 put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */ | |
322 put_le32(pb, asf->packet_size); /* packet size */ | |
323 put_le32(pb, asf->packet_size); /* packet size */ | |
324 put_le32(pb, bit_rate); /* Nominal data rate in bps */ | |
325 end_header(pb, hpos); | |
326 | |
327 /* unknown headers */ | |
328 hpos = put_header(pb, &head1_guid); | |
329 put_guid(pb, &head2_guid); | |
330 put_le32(pb, 6); | |
331 put_le16(pb, 0); | |
332 end_header(pb, hpos); | |
333 | |
334 /* title and other infos */ | |
335 if (has_title) { | |
336 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
|
337 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
|
338 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
|
339 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
|
340 if ( s->comment[0] ) { put_le16(pb, 2 * (strlen(s->comment ) + 1)); } else { put_le16(pb, 0); } |
0 | 341 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
|
342 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
|
343 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
|
344 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
|
345 if ( s->comment[0] ) put_str16_nolen(pb, s->comment); |
0 | 346 end_header(pb, hpos); |
347 } | |
348 | |
349 /* stream headers */ | |
350 for(n=0;n<s->nb_streams;n++) { | |
65 | 351 int64_t es_pos; |
716
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
352 uint8_t *er_spr = NULL; |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
353 int er_spr_len = 0; |
0 | 354 // ASFStream *stream = &asf->streams[n]; |
355 | |
356 enc = &s->streams[n]->codec; | |
357 asf->streams[n].num = n + 1; | |
358 asf->streams[n].seq = 0; | |
359 | |
716
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
360 |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
361 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
|
362 if (enc->codec_id == CODEC_ID_ADPCM_G726) { |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
363 er_spr = (uint8_t *)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
|
364 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
|
365 } |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
366 } |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
367 |
0 | 368 switch(enc->codec_type) { |
369 case CODEC_TYPE_AUDIO: | |
370 wav_extra_size = 0; | |
371 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
|
372 extra_size2 = er_spr_len; |
0 | 373 break; |
374 default: | |
375 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
|
376 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
|
377 extra_size = 0x33 + wav_extra_size; |
0 | 378 extra_size2 = 0; |
379 break; | |
380 } | |
381 | |
382 hpos = put_header(pb, &stream_header); | |
383 if (enc->codec_type == CODEC_TYPE_AUDIO) { | |
384 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
|
385 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
|
386 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
|
387 } else { |
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, &video_conceal_none); |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
389 } |
0 | 390 } else { |
391 put_guid(pb, &video_stream); | |
392 put_guid(pb, &video_conceal_none); | |
393 } | |
394 put_le64(pb, 0); /* ??? */ | |
395 es_pos = url_ftell(pb); | |
396 put_le32(pb, extra_size); /* wav header len */ | |
397 put_le32(pb, extra_size2); /* additional data len */ | |
398 put_le16(pb, n + 1); /* stream number */ | |
399 put_le32(pb, 0); /* ??? */ | |
400 | |
401 if (enc->codec_type == CODEC_TYPE_AUDIO) { | |
402 /* WAVEFORMATEX header */ | |
403 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
|
404 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
|
405 wavsize += 2; |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
406 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
|
407 } |
0 | 408 |
409 if (wavsize < 0) | |
410 return -1; | |
411 if (wavsize != extra_size) { | |
412 cur_pos = url_ftell(pb); | |
413 url_fseek(pb, es_pos, SEEK_SET); | |
414 put_le32(pb, wavsize); /* wav header len */ | |
415 url_fseek(pb, cur_pos, SEEK_SET); | |
416 } | |
716
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
417 /* ERROR Correction */ |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
418 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
|
419 put_buffer(pb, er_spr, er_spr_len); |
0 | 420 } else { |
421 put_le32(pb, enc->width); | |
422 put_le32(pb, enc->height); | |
423 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
|
424 put_le16(pb, 40 + enc->extradata_size); /* size */ |
0 | 425 |
426 /* BITMAPINFOHEADER header */ | |
427 put_bmp_header(pb, enc, codec_bmp_tags, 1); | |
428 } | |
429 end_header(pb, hpos); | |
430 } | |
431 | |
432 /* media comments */ | |
433 | |
434 hpos = put_header(pb, &codec_comment_header); | |
435 put_guid(pb, &codec_comment1_header); | |
436 put_le32(pb, s->nb_streams); | |
437 for(n=0;n<s->nb_streams;n++) { | |
438 AVCodec *p; | |
439 | |
440 enc = &s->streams[n]->codec; | |
441 p = avcodec_find_encoder(enc->codec_id); | |
442 | |
443 put_le16(pb, asf->streams[n].num); | |
444 put_str16(pb, p ? p->name : enc->codec_name); | |
445 put_le16(pb, 0); /* no parameters */ | |
196 | 446 |
447 | |
0 | 448 /* id */ |
449 if (enc->codec_type == CODEC_TYPE_AUDIO) { | |
450 put_le16(pb, 2); | |
196 | 451 if(!enc->codec_tag) |
452 enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id); | |
453 if(!enc->codec_tag) | |
454 return -1; | |
455 put_le16(pb, enc->codec_tag); | |
0 | 456 } else { |
457 put_le16(pb, 4); | |
196 | 458 if(!enc->codec_tag) |
459 enc->codec_tag = codec_get_tag(codec_bmp_tags, enc->codec_id); | |
460 if(!enc->codec_tag) | |
461 return -1; | |
462 put_le32(pb, enc->codec_tag); | |
0 | 463 } |
464 } | |
465 end_header(pb, hpos); | |
466 | |
467 /* patch the header size fields */ | |
468 | |
469 cur_pos = url_ftell(pb); | |
470 header_size = cur_pos - header_offset; | |
471 if (asf->is_streamed) { | |
472 header_size += 8 + 30 + 50; | |
473 | |
474 url_fseek(pb, header_offset - 10 - 30, SEEK_SET); | |
475 put_le16(pb, header_size); | |
476 url_fseek(pb, header_offset - 2 - 30, SEEK_SET); | |
477 put_le16(pb, header_size); | |
478 | |
479 header_size -= 8 + 30 + 50; | |
480 } | |
481 header_size += 24 + 6; | |
482 url_fseek(pb, header_offset - 14, SEEK_SET); | |
483 put_le64(pb, header_size); | |
484 url_fseek(pb, cur_pos, SEEK_SET); | |
485 | |
486 /* movie chunk, followed by packets of packet_size */ | |
487 asf->data_offset = cur_pos; | |
488 put_guid(pb, &data_header); | |
489 put_le64(pb, data_chunk_size); | |
490 put_guid(pb, &my_guid); | |
491 put_le64(pb, asf->nb_packets); /* nb packets */ | |
492 put_byte(pb, 1); /* ??? */ | |
493 put_byte(pb, 1); /* ??? */ | |
494 return 0; | |
495 } | |
496 | |
497 static int asf_write_header(AVFormatContext *s) | |
498 { | |
499 ASFContext *asf = s->priv_data; | |
500 | |
501 asf->packet_size = PACKET_SIZE; | |
502 asf->nb_packets = 0; | |
716
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
503 |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
504 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
|
505 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
|
506 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
|
507 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
|
508 asf->maximum_packet = 0; |
0 | 509 |
510 if (asf_write_header1(s, 0, 50) < 0) { | |
511 //av_free(asf); | |
512 return -1; | |
513 } | |
514 | |
515 put_flush_packet(&s->pb); | |
516 | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
517 asf->packet_nb_payloads = 0; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
518 asf->prev_packet_sent_time = 0; |
0 | 519 asf->packet_timestamp_start = -1; |
520 asf->packet_timestamp_end = -1; | |
521 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1, | |
522 NULL, NULL, NULL, NULL); | |
523 | |
524 return 0; | |
525 } | |
526 | |
527 static int asf_write_stream_header(AVFormatContext *s) | |
528 { | |
529 ASFContext *asf = s->priv_data; | |
530 | |
531 asf->is_streamed = 1; | |
532 | |
533 return asf_write_header(s); | |
534 } | |
535 | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
536 static int put_payload_parsing_info( |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
537 AVFormatContext *s, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
538 unsigned int sendtime, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
539 unsigned int duration, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
540 int nb_payloads, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
541 int padsize |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
542 ) |
0 | 543 { |
544 ASFContext *asf = s->priv_data; | |
545 ByteIOContext *pb = &s->pb; | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
546 int ppi_size, i; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
547 unsigned char *start_ppi_ptr = pb->buf_ptr; |
0 | 548 |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
549 int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
550 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
551 put_byte(pb, ASF_PACKET_ERROR_CORRECTION_FLAGS); |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
552 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
|
553 put_byte(pb, 0x0); |
0 | 554 } |
555 | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
556 if (asf->multi_payloads_present) |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
557 iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT; |
0 | 558 |
559 if (padsize > 0) { | |
560 if (padsize < 256) | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
561 iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE; |
0 | 562 else |
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_WORD; |
0 | 564 } |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
565 put_byte(pb, iLengthTypeFlags); |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
566 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
567 put_byte(pb, ASF_PPI_PROPERTY_FLAGS); |
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 if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD) |
0 | 570 put_le16(pb, padsize - 2); |
373
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_BYTE) |
0 | 572 put_byte(pb, padsize - 1); |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
573 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
574 put_le32(pb, sendtime); |
0 | 575 put_le16(pb, duration); |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
576 if (asf->multi_payloads_present) |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
577 put_byte(pb, nb_payloads | ASF_PAYLOAD_FLAGS); |
0 | 578 |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
579 ppi_size = pb->buf_ptr - start_ppi_ptr; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
580 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
581 return ppi_size; |
0 | 582 } |
583 | |
584 static void flush_packet(AVFormatContext *s) | |
585 { | |
586 ASFContext *asf = s->priv_data; | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
587 int packet_hdr_size, packet_filled_size; |
0 | 588 |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
589 if (asf->is_streamed) { |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
590 put_chunk(s, 0x4424, asf->packet_size, 0); |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
591 } |
0 | 592 |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
593 packet_hdr_size = put_payload_parsing_info( |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
594 s, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
595 asf->packet_timestamp_start, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
596 asf->packet_timestamp_end - asf->packet_timestamp_start, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
597 asf->packet_nb_payloads, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
598 asf->packet_size_left |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
599 ); |
0 | 600 |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
601 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
|
602 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
|
603 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
604 put_buffer(&s->pb, asf->packet_buf, asf->packet_size - packet_hdr_size); |
0 | 605 |
606 put_flush_packet(&s->pb); | |
607 asf->nb_packets++; | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
608 asf->packet_nb_payloads = 0; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
609 asf->prev_packet_sent_time = asf->packet_timestamp_start; |
0 | 610 asf->packet_timestamp_start = -1; |
611 asf->packet_timestamp_end = -1; | |
612 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1, | |
613 NULL, NULL, NULL, NULL); | |
614 } | |
615 | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
616 static void put_payload_header( |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
617 AVFormatContext *s, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
618 ASFStream *stream, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
619 int presentation_time, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
620 int m_obj_size, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
621 int m_obj_offset, |
470 | 622 int payload_len, |
623 int flags | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
624 ) |
0 | 625 { |
626 ASFContext *asf = s->priv_data; | |
627 ByteIOContext *pb = &asf->pb; | |
628 int val; | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
629 |
0 | 630 val = stream->num; |
470 | 631 if (flags & PKT_FLAG_KEY) |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
632 val |= ASF_PL_FLAG_KEY_FRAME; |
0 | 633 put_byte(pb, val); |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
634 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
635 put_byte(pb, stream->seq); //Media object number |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
636 put_le32(pb, m_obj_offset); //Offset Into Media Object |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
637 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
638 // 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
|
639 // The first 4 bytes of data shall contain the |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
640 // Size of the Media Object that the payload belongs to. |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
641 // The next 4 bytes of data shall contain the |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
642 // 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
|
643 put_byte(pb, ASF_PAYLOAD_REPLICATED_DATA_LENGTH); |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
644 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
645 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
|
646 put_le32(pb, presentation_time);//Replicated Data - Presentation Time |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
647 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
648 if (asf->multi_payloads_present){ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
649 put_le16(pb, payload_len); //payload length |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
650 } |
0 | 651 } |
652 | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
653 static void put_frame( |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
654 AVFormatContext *s, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
655 ASFStream *stream, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
656 int timestamp, |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
657 const uint8_t *buf, |
470 | 658 int m_obj_size, |
659 int flags | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
660 ) |
0 | 661 { |
662 ASFContext *asf = s->priv_data; | |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
663 int m_obj_offset, payload_len, frag_len1; |
0 | 664 |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
665 m_obj_offset = 0; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
666 while (m_obj_offset < m_obj_size) { |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
667 payload_len = m_obj_size - m_obj_offset; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
668 if (asf->packet_timestamp_start == -1) { |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
669 asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT); |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
670 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
671 if (asf->multi_payloads_present){ |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
672 asf->packet_size_left = PACKET_SIZE; //For debug |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
673 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
|
674 frag_len1 = MULTI_PAYLOAD_CONSTANT - 1; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
675 } |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
676 else { |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
677 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
|
678 frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
679 } |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
680 if (asf->prev_packet_sent_time > timestamp) |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
681 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
|
682 else |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
683 asf->packet_timestamp_start = timestamp; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
684 } |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
685 else { |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
686 // multi payloads |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
687 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
|
688 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
689 if (asf->prev_packet_sent_time > timestamp) |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
690 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
|
691 else if (asf->packet_timestamp_start >= timestamp) |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
692 asf->packet_timestamp_start = timestamp; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
693 } |
0 | 694 if (frag_len1 > 0) { |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
695 if (payload_len > frag_len1) |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
696 payload_len = frag_len1; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
697 else if (payload_len == (frag_len1 - 1)) |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
698 payload_len = frag_len1 - 2; //additional byte need to put padding length |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
699 |
470 | 700 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
|
701 put_buffer(&asf->pb, buf, payload_len); |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
702 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
703 if (asf->multi_payloads_present) |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
704 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
|
705 else |
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_SINGLE_PAYLOAD); |
0 | 707 asf->packet_timestamp_end = timestamp; |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
708 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
709 asf->packet_nb_payloads++; |
0 | 710 } else { |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
711 payload_len = 0; |
0 | 712 } |
373
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
713 m_obj_offset += payload_len; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
714 buf += payload_len; |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
715 |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
716 if (!asf->multi_payloads_present) |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
717 flush_packet(s); |
e47d9c8e2054
asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
372
diff
changeset
|
718 else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + 1)) |
0 | 719 flush_packet(s); |
720 } | |
721 stream->seq++; | |
722 } | |
723 | |
468 | 724 static int asf_write_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 725 { |
726 ASFContext *asf = s->priv_data; | |
727 ASFStream *stream; | |
65 | 728 int64_t duration; |
0 | 729 AVCodecContext *codec; |
716
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
730 int64_t packet_st,pts; |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
731 int start_sec,i; |
0 | 732 |
468 | 733 codec = &s->streams[pkt->stream_index]->codec; |
734 stream = &asf->streams[pkt->stream_index]; | |
0 | 735 |
716
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
736 //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
|
737 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
|
738 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
|
739 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
|
740 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
|
741 codec->sample_rate; |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
742 } else { |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
743 duration = av_rescale(codec->frame_number * (int64_t)codec->frame_rate_base, 10000000, codec->frame_rate); |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
744 } |
0 | 745 } else { |
716
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
746 duration = pts * 10000; |
0 | 747 } |
748 if (duration > asf->duration) | |
749 asf->duration = duration; | |
750 | |
716
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
751 packet_st = asf->nb_packets; |
470 | 752 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
|
753 |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
754 /* check index */ |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
755 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
|
756 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
|
757 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
|
758 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
|
759 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
|
760 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
|
761 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
|
762 } |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
763 // store |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
764 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
|
765 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
|
766 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
|
767 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
|
768 } |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
769 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
|
770 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
|
771 } |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
772 } |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
773 return 0; |
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 |
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 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
|
778 { |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
779 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
|
780 int i; |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
781 |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
782 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
|
783 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
|
784 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
|
785 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
|
786 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
|
787 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
|
788 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
|
789 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
|
790 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
|
791 } |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
792 |
0 | 793 return 0; |
794 } | |
795 | |
796 static int asf_write_trailer(AVFormatContext *s) | |
797 { | |
798 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
|
799 int64_t file_size,data_size; |
0 | 800 |
801 /* flush the current packet */ | |
802 if (asf->pb.buf_ptr > asf->pb.buffer) | |
803 flush_packet(s); | |
804 | |
716
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
805 /* write index */ |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
806 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
|
807 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
|
808 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
|
809 } |
55081ada3aad
31_ASF_compatibility_with_WMP_and_add_index.patch by (Calcium | calcium nurs or jp)
michael
parents:
672
diff
changeset
|
810 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
|
811 |
0 | 812 if (asf->is_streamed) { |
813 put_chunk(s, 0x4524, 0, 0); /* end of stream */ | |
814 } else { | |
815 /* rewrite an updated header */ | |
816 file_size = url_ftell(&s->pb); | |
817 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
|
818 asf_write_header1(s, file_size, data_size - asf->data_offset); |
0 | 819 } |
820 | |
821 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
|
822 av_free(asf->index_ptr); |
0 | 823 return 0; |
824 } | |
825 | |
372
2e12cd1b68ed
split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
370
diff
changeset
|
826 AVOutputFormat asf_oformat = { |
0 | 827 "asf", |
828 "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
|
829 "video/x-ms-asf", |
672 | 830 "asf,wmv,wma", |
0 | 831 sizeof(ASFContext), |
832 #ifdef CONFIG_MP3LAME | |
232 | 833 CODEC_ID_MP3, |
0 | 834 #else |
835 CODEC_ID_MP2, | |
836 #endif | |
837 CODEC_ID_MSMPEG4V3, | |
838 asf_write_header, | |
839 asf_write_packet, | |
840 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
|
841 .flags = AVFMT_GLOBALHEADER, |
0 | 842 }; |
843 | |
372
2e12cd1b68ed
split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents:
370
diff
changeset
|
844 AVOutputFormat asf_stream_oformat = { |
0 | 845 "asf_stream", |
846 "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
|
847 "video/x-ms-asf", |
672 | 848 "asf,wmv,wma", |
0 | 849 sizeof(ASFContext), |
850 #ifdef CONFIG_MP3LAME | |
232 | 851 CODEC_ID_MP3, |
0 | 852 #else |
853 CODEC_ID_MP2, | |
854 #endif | |
855 CODEC_ID_MSMPEG4V3, | |
856 asf_write_stream_header, | |
857 asf_write_packet, | |
858 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
|
859 .flags = AVFMT_GLOBALHEADER, |
0 | 860 }; |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
861 #endif //CONFIG_ENCODERS |