annotate asf-enc.c @ 547:b832a27355ec libavformat

initial dts fix
author michael
date Sun, 03 Oct 2004 12:58:14 +0000
parents 334e08488ad1
children 9a6a30f512b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
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 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22
348
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
23 #undef NDEBUG
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
24 #include <assert.h>
ca519d041ea1 memleak fix
michael
parents: 347
diff changeset
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
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
28 #define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE 0x2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
29 #define ASF_PACKET_ERROR_CORRECTION_FLAGS (\
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
30 ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT | \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
31 ASF_PACKET_ERROR_CORRECTION_DATA_SIZE\
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
32 )
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
33
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
34 #if (ASF_PACKET_ERROR_CORRECTION_FLAGS != 0)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
35 # 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
36 #else
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
37 # 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
38 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
39
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
40 #define ASF_PPI_PROPERTY_FLAGS (\
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
41 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
42 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
43 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
44 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
45 )
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
46
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
47 #define ASF_PPI_LENGTH_TYPE_FLAGS 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
48
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
49 #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
50
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
51 #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
52 # define ASF_PPI_SEQUENCE_FIELD_SIZE 1
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
53 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
54 #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
55 # define ASF_PPI_SEQUENCE_FIELD_SIZE 2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
56 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
57 #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
58 # define ASF_PPI_SEQUENCE_FIELD_SIZE 4
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
59 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
60 #ifndef ASF_PPI_SEQUENCE_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
61 # define ASF_PPI_SEQUENCE_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
62 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
63
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
64
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
65 #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
66 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 1
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
67 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
68 #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
69 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
70 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
71 #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
72 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 4
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
73 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
74 #ifndef ASF_PPI_PACKET_LENGTH_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
75 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
76 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
77
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
78 #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
79 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 1
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 #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
82 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
83 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
84 #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
85 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 4
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
86 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
87 #ifndef ASF_PPI_PADDING_LENGTH_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
88 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
89 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
90
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
91 #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
92 # 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
93 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
94 #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
95 # 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
96 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
97 #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
98 # 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
99 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
100 #ifndef ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
101 # 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
102 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
103
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
104 #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
105 # 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
106 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
107 #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
108 # 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
109 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
110 #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
111 # 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
112 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
113 #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
114 # 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
115 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
116
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
117 #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
118 # 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
119 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
120 #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
121 # 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
122 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
123 #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
124 # 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
125 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
126 #ifndef ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
127 # 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
128 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
129
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
130 #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
131 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 1
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 #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
134 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 2
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
135 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
136 #ifndef ASF_PAYLOAD_LENGTH_FIELD_SIZE
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
137 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 0
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
138 #endif
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
139
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
140 #define PACKET_HEADER_MIN_SIZE (\
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
141 ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
142 ASF_PACKET_ERROR_CORRECTION_DATA_SIZE + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
143 1 + /*Length Type Flags*/ \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
144 1 + /*Property Flags*/ \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
145 ASF_PPI_PACKET_LENGTH_FIELD_SIZE + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
146 ASF_PPI_SEQUENCE_FIELD_SIZE + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
147 ASF_PPI_PADDING_LENGTH_FIELD_SIZE + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
148 4 + /*Send Time Field*/ \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
149 2 /*Duration Field*/ \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
150 )
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
151
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
152
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
153 // 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
154 #define ASF_PAYLOAD_REPLICATED_DATA_LENGTH 0x08
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 #define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD (\
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
157 1 + /*Stream Number*/ \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
158 ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
159 ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
160 ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
161 ASF_PAYLOAD_REPLICATED_DATA_LENGTH \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
162 )
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
163
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
164 #define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS (\
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
165 1 + /*Stream Number*/ \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
166 ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
167 ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
168 ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
169 ASF_PAYLOAD_REPLICATED_DATA_LENGTH + \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
170 ASF_PAYLOAD_LENGTH_FIELD_SIZE \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
171 )
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
172
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
173 #define SINGLE_PAYLOAD_DATA_LENGTH (\
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
174 PACKET_SIZE - \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
175 PACKET_HEADER_MIN_SIZE - \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
176 PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
177 )
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
178
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
179 #define MULTI_PAYLOAD_CONSTANT (\
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
180 PACKET_SIZE - \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
181 PACKET_HEADER_MIN_SIZE - \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
182 1 - /*Payload Flags*/ \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
183 2*PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
184 )
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
185
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
186 static int preroll_time = 2000;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
187
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 static void put_guid(ByteIOContext *s, const GUID *g)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 put_le32(s, g->v1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 put_le16(s, g->v2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 put_le16(s, g->v3);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 for(i=0;i<8;i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 put_byte(s, g->v4[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 static void put_str16(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 put_le16(s,strlen(tag) + 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 for(;;) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
205 c = (uint8_t)*tag++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 put_le16(s, c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 static void put_str16_nolen(ByteIOContext *s, const char *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 int c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 for(;;) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
217 c = (uint8_t)*tag++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 put_le16(s, c);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 if (c == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
224 static int64_t put_header(ByteIOContext *pb, const GUID *g)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
226 int64_t pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 put_guid(pb, g);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 put_le64(pb, 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 return pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 /* update header size */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
235 static void end_header(ByteIOContext *pb, int64_t pos)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
237 int64_t pos1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 pos1 = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 url_fseek(pb, pos + 16, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 put_le64(pb, pos1 - pos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 url_fseek(pb, pos1, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 /* write an asf chunk (only used in streaming case) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 int length;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 length = payload_length + 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 put_le16(pb, type);
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
254 put_le16(pb, length); //size
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
255 put_le32(pb, asf->seqno);//sequence number
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 put_le16(pb, flags); /* unknown bytes */
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
257 put_le16(pb, length); //size_confirm
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 asf->seqno++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 /* convert from unix to windows time */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
262 static int64_t unix_to_file_time(int ti)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
264 int64_t t;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
266 t = ti * int64_t_C(10000000);
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
267 t += int64_t_C(116444736000000000);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 return t;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 /* write the header (used two times if non streamed) */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
272 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
273 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 int has_title;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 AVCodecContext *enc;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
279 int64_t header_offset, cur_pos, hpos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 int bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 bit_rate = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287
462
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 373
diff changeset
288 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
289
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 bit_rate += enc->bit_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 put_guid(pb, &asf_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 put_le64(pb, -1); /* header length, will be patched after */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 put_byte(pb, 2); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 /* file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 header_offset = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 hpos = put_header(pb, &file_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 put_guid(pb, &my_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 put_le64(pb, file_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 file_time = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 put_le64(pb, unix_to_file_time(file_time));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 put_le64(pb, asf->nb_packets); /* number of packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 put_le64(pb, asf->duration); /* end time stamp (in 100ns units) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 put_le64(pb, asf->duration); /* duration (in 100ns units) */
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
313 put_le32(pb, preroll_time); /* start time stamp */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 put_le32(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 put_le32(pb, asf->packet_size); /* packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 put_le32(pb, asf->packet_size); /* packet size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 put_le32(pb, bit_rate); /* Nominal data rate in bps */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 /* unknown headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 hpos = put_header(pb, &head1_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 put_guid(pb, &head2_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 put_le32(pb, 6);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 /* title and other infos */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 if (has_title) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 hpos = put_header(pb, &comment_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 put_le16(pb, 2 * (strlen(s->title) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 put_le16(pb, 2 * (strlen(s->author) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 put_le16(pb, 2 * (strlen(s->copyright) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 put_le16(pb, 2 * (strlen(s->comment) + 1));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 put_le16(pb, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 put_str16_nolen(pb, s->title);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 put_str16_nolen(pb, s->author);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 put_str16_nolen(pb, s->copyright);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 put_str16_nolen(pb, s->comment);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 /* stream headers */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344 for(n=0;n<s->nb_streams;n++) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
345 int64_t es_pos;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 // ASFStream *stream = &asf->streams[n];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 asf->streams[n].num = n + 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 asf->streams[n].seq = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 switch(enc->codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 case CODEC_TYPE_AUDIO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 wav_extra_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355 extra_size = 18 + wav_extra_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 extra_size2 = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 wav_extra_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 extra_size = 0x33;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 extra_size2 = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 hpos = put_header(pb, &stream_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368 put_guid(pb, &audio_stream);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 put_guid(pb, &audio_conceal_none);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 put_guid(pb, &video_stream);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 put_guid(pb, &video_conceal_none);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 put_le64(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 es_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 put_le32(pb, extra_size); /* wav header len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 put_le32(pb, extra_size2); /* additional data len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 put_le16(pb, n + 1); /* stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 put_le32(pb, 0); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382 /* WAVEFORMATEX header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 int wavsize = put_wav_header(pb, enc);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 if (wavsize < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387 if (wavsize != extra_size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 cur_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 url_fseek(pb, es_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390 put_le32(pb, wavsize); /* wav header len */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 url_fseek(pb, cur_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 put_le32(pb, enc->width);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 put_le32(pb, enc->height);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 put_byte(pb, 2); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 put_le16(pb, 40); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 /* BITMAPINFOHEADER header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 put_bmp_header(pb, enc, codec_bmp_tags, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 /* media comments */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 hpos = put_header(pb, &codec_comment_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 put_guid(pb, &codec_comment1_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 put_le32(pb, s->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 for(n=0;n<s->nb_streams;n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 AVCodec *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 enc = &s->streams[n]->codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 p = avcodec_find_encoder(enc->codec_id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 put_le16(pb, asf->streams[n].num);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 put_str16(pb, p ? p->name : enc->codec_name);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 put_le16(pb, 0); /* no parameters */
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
419
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
420
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 /* id */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 if (enc->codec_type == CODEC_TYPE_AUDIO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 put_le16(pb, 2);
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
424 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
425 enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
426 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
427 return -1;
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
428 put_le16(pb, enc->codec_tag);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 put_le16(pb, 4);
196
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
431 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
432 enc->codec_tag = codec_get_tag(codec_bmp_tags, enc->codec_id);
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
433 if(!enc->codec_tag)
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
434 return -1;
01bec1059bdf use codec_tag for encoding too
michaelni
parents: 188
diff changeset
435 put_le32(pb, enc->codec_tag);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 end_header(pb, hpos);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 /* patch the header size fields */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 cur_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 header_size = cur_pos - header_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 header_size += 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 put_le16(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 header_size -= 8 + 30 + 50;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 header_size += 24 + 6;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 url_fseek(pb, header_offset - 14, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456 put_le64(pb, header_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 url_fseek(pb, cur_pos, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 /* movie chunk, followed by packets of packet_size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 asf->data_offset = cur_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461 put_guid(pb, &data_header);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 put_le64(pb, data_chunk_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 put_guid(pb, &my_guid);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 put_le64(pb, asf->nb_packets); /* nb packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 put_byte(pb, 1); /* ??? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 static int asf_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 asf->packet_size = PACKET_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 asf->nb_packets = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 if (asf_write_header1(s, 0, 50) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 //av_free(asf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
484 asf->packet_nb_payloads = 0;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
485 asf->prev_packet_sent_time = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 static int asf_write_stream_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 asf->is_streamed = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 return asf_write_header(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
503 static int put_payload_parsing_info(
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
504 AVFormatContext *s,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
505 unsigned int sendtime,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
506 unsigned int duration,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
507 int nb_payloads,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
508 int padsize
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
509 )
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 ByteIOContext *pb = &s->pb;
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
513 int ppi_size, i;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
514 unsigned char *start_ppi_ptr = pb->buf_ptr;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
516 int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
517
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
518 put_byte(pb, ASF_PACKET_ERROR_CORRECTION_FLAGS);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
519 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
520 put_byte(pb, 0x0);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
523 if (asf->multi_payloads_present)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
524 iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 if (padsize > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 if (padsize < 256)
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
528 iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 else
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
530 iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 }
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
532 put_byte(pb, iLengthTypeFlags);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
533
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
534 put_byte(pb, ASF_PPI_PROPERTY_FLAGS);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
535
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
536 if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 put_le16(pb, padsize - 2);
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
538 if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 put_byte(pb, padsize - 1);
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
540
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
541 put_le32(pb, sendtime);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 put_le16(pb, duration);
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
543 if (asf->multi_payloads_present)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
544 put_byte(pb, nb_payloads | ASF_PAYLOAD_FLAGS);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
546 ppi_size = pb->buf_ptr - start_ppi_ptr;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
547
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
548 return ppi_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551 static void flush_packet(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 ASFContext *asf = s->priv_data;
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
554 int packet_hdr_size, packet_filled_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
556 if (asf->is_streamed) {
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
557 put_chunk(s, 0x4424, asf->packet_size, 0);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
558 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
560 packet_hdr_size = put_payload_parsing_info(
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
561 s,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
562 asf->packet_timestamp_start,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
563 asf->packet_timestamp_end - asf->packet_timestamp_start,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
564 asf->packet_nb_payloads,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
565 asf->packet_size_left
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
566 );
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
568 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
569 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
570
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
571 put_buffer(&s->pb, asf->packet_buf, asf->packet_size - packet_hdr_size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 asf->nb_packets++;
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
575 asf->packet_nb_payloads = 0;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
576 asf->prev_packet_sent_time = asf->packet_timestamp_start;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 asf->packet_timestamp_start = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 asf->packet_timestamp_end = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580 NULL, NULL, NULL, NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
583 static void put_payload_header(
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
584 AVFormatContext *s,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
585 ASFStream *stream,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
586 int presentation_time,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
587 int m_obj_size,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
588 int m_obj_offset,
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
589 int payload_len,
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
590 int flags
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
591 )
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 ByteIOContext *pb = &asf->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 int val;
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
596
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 val = stream->num;
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
598 if (flags & PKT_FLAG_KEY)
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
599 val |= ASF_PL_FLAG_KEY_FRAME;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 put_byte(pb, val);
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
601
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
602 put_byte(pb, stream->seq); //Media object number
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
603 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
604
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
605 // 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
606 // 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
607 // 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
608 // 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
609 // 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
610 put_byte(pb, ASF_PAYLOAD_REPLICATED_DATA_LENGTH);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
611
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
612 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
613 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
614
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
615 if (asf->multi_payloads_present){
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
616 put_le16(pb, payload_len); //payload length
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
617 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
620 static void put_frame(
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
621 AVFormatContext *s,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
622 ASFStream *stream,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
623 int timestamp,
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
624 const uint8_t *buf,
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
625 int m_obj_size,
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
626 int flags
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
627 )
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629 ASFContext *asf = s->priv_data;
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
630 int m_obj_offset, payload_len, frag_len1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
631
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
632 m_obj_offset = 0;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
633 while (m_obj_offset < m_obj_size) {
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
634 payload_len = m_obj_size - m_obj_offset;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
635 if (asf->packet_timestamp_start == -1) {
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
636 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
637
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
638 if (asf->multi_payloads_present){
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
639 asf->packet_size_left = PACKET_SIZE; //For debug
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
640 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
641 frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
642 }
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
643 else {
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
644 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
645 frag_len1 = SINGLE_PAYLOAD_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 if (asf->prev_packet_sent_time > timestamp)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
648 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
649 else
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
650 asf->packet_timestamp_start = timestamp;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
651 }
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
652 else {
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
653 // multi payloads
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
654 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
655
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
656 if (asf->prev_packet_sent_time > timestamp)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
657 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
658 else if (asf->packet_timestamp_start >= timestamp)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
659 asf->packet_timestamp_start = timestamp;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
660 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
661 if (frag_len1 > 0) {
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
662 if (payload_len > frag_len1)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
663 payload_len = frag_len1;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
664 else if (payload_len == (frag_len1 - 1))
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
665 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
666
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
667 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
668 put_buffer(&asf->pb, buf, payload_len);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
669
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
670 if (asf->multi_payloads_present)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
671 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
672 else
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
673 asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674 asf->packet_timestamp_end = timestamp;
373
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 asf->packet_nb_payloads++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
677 } else {
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
678 payload_len = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
679 }
373
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
680 m_obj_offset += payload_len;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
681 buf += payload_len;
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
682
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
683 if (!asf->multi_payloads_present)
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
684 flush_packet(s);
e47d9c8e2054 asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 372
diff changeset
685 else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + 1))
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
686 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
687 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 stream->seq++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
689 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
690
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
691 static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
692 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
693 ASFContext *asf = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
694 ASFStream *stream;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
695 int64_t duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
696 AVCodecContext *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
697
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
698 codec = &s->streams[pkt->stream_index]->codec;
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
699 stream = &asf->streams[pkt->stream_index];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
700
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
701 //XXX /FIXME use duration from AVPacket
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702 if (codec->codec_type == CODEC_TYPE_AUDIO) {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
703 duration = (codec->frame_number * codec->frame_size * int64_t_C(10000000)) /
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
704 codec->sample_rate;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
705 } else {
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
706 duration = av_rescale(codec->frame_number * codec->frame_rate_base, 10000000, codec->frame_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
707 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
708 if (duration > asf->duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709 asf->duration = duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710
470
334e08488ad1 correctly interleave packets during encoding
michael
parents: 468
diff changeset
711 put_frame(s, stream, pkt->pts, pkt->data, pkt->size, pkt->flags);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
712 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
713 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715 static int asf_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717 ASFContext *asf = s->priv_data;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 14
diff changeset
718 int64_t file_size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720 /* flush the current packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721 if (asf->pb.buf_ptr > asf->pb.buffer)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 flush_packet(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
723
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
724 if (asf->is_streamed) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
725 put_chunk(s, 0x4524, 0, 0); /* end of stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
726 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727 /* rewrite an updated header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728 file_size = url_ftell(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 url_fseek(&s->pb, 0, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
730 asf_write_header1(s, file_size, file_size - asf->data_offset);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
731 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
732
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
733 put_flush_packet(&s->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
734 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
735 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
736
372
2e12cd1b68ed split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 370
diff changeset
737 AVOutputFormat asf_oformat = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
738 "asf",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
739 "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
740 "video/x-ms-asf",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
741 "asf,wmv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
742 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
743 #ifdef CONFIG_MP3LAME
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
744 CODEC_ID_MP3,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
746 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
747 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
748 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
749 asf_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
750 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
751 asf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
752 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
753
372
2e12cd1b68ed split asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>)
michael
parents: 370
diff changeset
754 AVOutputFormat asf_stream_oformat = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
755 "asf_stream",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
756 "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
757 "video/x-ms-asf",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
758 "asf,wmv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
759 sizeof(ASFContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 #ifdef CONFIG_MP3LAME
232
eb90c0a5a1ba CODEC_ID_MP3LAME is obsolete
bellard
parents: 196
diff changeset
761 CODEC_ID_MP3,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
763 CODEC_ID_MP2,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765 CODEC_ID_MSMPEG4V3,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
766 asf_write_stream_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 asf_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
768 asf_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 };
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 241
diff changeset
770 #endif //CONFIG_ENCODERS