31 #define ASF_INDEXED_INTERVAL 10000000
32 #define ASF_INDEX_BLOCK (1<<9)
33 #define ASF_PAYLOADS_PER_PACKET 63
35 #define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE 0x2
36 #define ASF_PACKET_ERROR_CORRECTION_FLAGS \
37 (ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT | \
38 ASF_PACKET_ERROR_CORRECTION_DATA_SIZE)
40 #if (ASF_PACKET_ERROR_CORRECTION_FLAGS != 0)
41 # define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 1
43 # define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 0
46 #define ASF_PPI_PROPERTY_FLAGS \
47 (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE | \
48 ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD | \
49 ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE | \
50 ASF_PL_FLAG_STREAM_NUMBER_LENGTH_FIELD_IS_BYTE)
52 #define ASF_PPI_LENGTH_TYPE_FLAGS 0
54 #define ASF_PAYLOAD_FLAGS ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD
56 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
57 # define ASF_PPI_SEQUENCE_FIELD_SIZE 1
59 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
60 # define ASF_PPI_SEQUENCE_FIELD_SIZE 2
62 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
63 # define ASF_PPI_SEQUENCE_FIELD_SIZE 4
65 #ifndef ASF_PPI_SEQUENCE_FIELD_SIZE
66 # define ASF_PPI_SEQUENCE_FIELD_SIZE 0
69 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
70 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 1
72 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
73 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 2
75 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
76 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 4
78 #ifndef ASF_PPI_PACKET_LENGTH_FIELD_SIZE
79 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 0
82 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
83 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 1
85 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
86 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 2
88 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
89 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 4
91 #ifndef ASF_PPI_PADDING_LENGTH_FIELD_SIZE
92 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 0
95 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
96 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 1
98 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
99 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 2
101 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
102 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 4
104 #ifndef ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE
105 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 0
108 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
109 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 1
111 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
112 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 2
114 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
115 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 4
117 #ifndef ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE
118 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 0
121 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
122 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 1
124 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
125 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 2
127 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
128 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 4
130 #ifndef ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE
131 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 0
134 #if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_BYTE == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
135 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 1
137 #if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
138 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 2
140 #ifndef ASF_PAYLOAD_LENGTH_FIELD_SIZE
141 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 0
144 #define PACKET_HEADER_MIN_SIZE \
145 (ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE + \
146 ASF_PACKET_ERROR_CORRECTION_DATA_SIZE + \
149 ASF_PPI_PACKET_LENGTH_FIELD_SIZE + \
150 ASF_PPI_SEQUENCE_FIELD_SIZE + \
151 ASF_PPI_PADDING_LENGTH_FIELD_SIZE + \
156 #define ASF_PAYLOAD_REPLICATED_DATA_LENGTH 0x08
158 #define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD \
160 ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
161 ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
162 ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
163 ASF_PAYLOAD_REPLICATED_DATA_LENGTH)
165 #define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \
167 ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
168 ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
169 ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
170 ASF_PAYLOAD_REPLICATED_DATA_LENGTH + \
171 ASF_PAYLOAD_LENGTH_FIELD_SIZE)
173 #define SINGLE_PAYLOAD_DATA_LENGTH \
175 PACKET_HEADER_MIN_SIZE - \
176 PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD)
178 #define MULTI_PAYLOAD_CONSTANT \
180 PACKET_HEADER_MIN_SIZE - \
182 2 * PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS)
184 #define DATA_HEADER_SIZE 50
253 #define PREROLL_TIME 3100
293 int payload_length,
int flags)
299 length = payload_length + 8;
313 t = ti * INT64_C(10000000);
314 t += INT64_C(116444736000000000);
324 if (pres_time <= asf->index_ptr[i].send_time)
330 return send_time / 10000;
378 int64_t data_chunk_size)
383 int header_size,
n, extra_size, extra_size2, wav_extra_size, file_time;
384 int has_title, has_aspect_ratio = 0;
387 int64_t header_offset, cur_pos, hpos;
400 has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4];
447 if (has_aspect_ratio) {
449 avio_wl32(pb, 26 + has_aspect_ratio * 84);
502 if (metadata_count) {
531 extra_size = 18 + wav_extra_size;
537 extra_size = 0x33 + wav_extra_size;
563 if (wavsize != extra_size) {
612 desc =
"Windows Media Audio V8";
614 desc = codec_desc ? codec_desc->
name :
NULL;
651 header_size = cur_pos - header_offset;
655 avio_seek(pb, header_offset - 10 - 30, SEEK_SET);
657 avio_seek(pb, header_offset - 2 - 30, SEEK_SET);
662 header_size += 24 + 6;
663 avio_seek(pb, header_offset - 14, SEEK_SET);
725 unsigned sendtime,
unsigned duration,
726 int nb_payloads,
int padsize)
775 int packet_hdr_size, packet_filled_size;
789 av_assert0(packet_hdr_size <= asf->packet_size_left);
804 int64_t presentation_time,
int m_obj_size,
805 int m_obj_offset,
int payload_len,
int flags)
827 avio_wl32(pb, (uint32_t) presentation_time);
836 int m_obj_size,
int flags)
839 int m_obj_offset, payload_len, frag_len1;
842 while (m_obj_offset < m_obj_size) {
843 payload_len = m_obj_size - m_obj_offset;
860 if (frag_len1 < payload_len &&
867 if (payload_len > frag_len1)
868 payload_len = frag_len1;
869 else if (payload_len == (frag_len1 - 1))
870 payload_len = frag_len1 - 2;
873 m_obj_size, m_obj_offset, payload_len, flags);
886 m_obj_offset += payload_len;
900 uint32_t packet_number, uint16_t packet_count,
901 uint64_t packet_offset)
947 uint32_t packet_number;
974 uint16_t packet_count = asf->
nb_packets - packet_number;
975 ret =
update_index(s, start_sec, packet_number, packet_count, offset);
985 uint16_t max, uint32_t
count)
991 avio_wl64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2) * count);
996 for (i = 0; i <
count; i++) {
1007 int64_t file_size, data_size;
1036 #if CONFIG_ASF_MUXER
1040 .mime_type =
"video/x-ms-asf",
1041 .extensions =
"asf,wmv,wma",
1055 #if CONFIG_ASF_STREAM_MUXER
1057 .
name =
"asf_stream",
1059 .mime_type =
"video/x-ms-asf",
1060 .extensions =
"asf,wmv,wma",
unsigned int nb_chapters
Number of chapters in AVChapter array.
const ff_asf_guid ff_asf_header
const char const char void * val
void avio_wl16(AVIOContext *s, unsigned int val)
static int asf_write_markers(AVFormatContext *s)
#define ASF_PAYLOAD_FLAGS
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
const ff_asf_guid ff_asf_codec_comment_header
const ff_asf_guid ff_asf_metadata_header
#define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD
void ff_put_guid(AVIOContext *s, const ff_asf_guid *g)
unsigned char * buf_ptr
Current position in the buffer.
unsigned int packet_nb_payloads
static int64_t unix_to_file_time(int ti)
#define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS
static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
uint64_t data_offset
beginning of the first data packet
static int asf_write_index(AVFormatContext *s, const ASFIndex *index, uint16_t max, uint32_t count)
uint32_t next_packet_number
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
unsigned char * buffer
Start of the buffer.
static int put_payload_parsing_info(AVFormatContext *s, unsigned sendtime, unsigned duration, int nb_payloads, int padsize)
static int asf_write_trailer(AVFormatContext *s)
uint16_t next_packet_count
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
const ff_asf_guid ff_asf_reserved_4
const ff_asf_guid ff_asf_data_header
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void avio_wl32(AVIOContext *s, unsigned int val)
const ff_asf_guid ff_asf_audio_stream
static int asf_write_header(AVFormatContext *s)
ASFStream streams[128]
it's max number and it's not that big
AVStream ** streams
A list of all streams in the file.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int64_t max_interleave_delta
Maximum buffering duration for interleaving.
#define ASF_PPI_LENGTH_TYPE_FLAGS
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void avio_wl64(AVIOContext *s, uint64_t val)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
AVDictionary * metadata
Metadata that applies to the whole file.
const ff_asf_guid ff_asf_head1_guid
const ff_asf_guid ff_asf_simple_index_header
const ff_asf_guid ff_asf_head2_guid
static void put_payload_header(AVFormatContext *s, ASFStream *stream, int64_t presentation_time, int m_obj_size, int m_obj_offset, int payload_len, int flags)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int64_t packet_timestamp_start
const ff_asf_guid ff_asf_video_conceal_none
simple assert() macros that are a bit more flexible than ISO C assert().
#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD
static const uint8_t offset[127][2]
const AVCodecTag ff_codec_wav_tags[]
int flags
A combination of AV_PKT_FLAG values.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
AVCodecContext * codec
Codec context associated with this stream.
#define ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int bit_rate
the average bitrate
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
const AVCodecTag ff_codec_bmp_tags[]
int width
picture width / height.
static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
#define ASF_PACKET_ERROR_CORRECTION_FLAGS
GLsizei GLboolean const GLfloat * value
const ff_asf_guid ff_asf_extended_content_header
static int write_trailer(AVFormatContext *s1)
static int32_t get_send_time(ASFContext *asf, int64_t pres_time, uint64_t *offset)
#define ASF_PAYLOADS_PER_PACKET
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
#define ASF_PAYLOAD_REPLICATED_DATA_LENGTH
int avoid_negative_ts
Avoid negative timestamps during muxing.
const ff_asf_guid ff_asf_my_guid
#define FF_ARRAY_ELEMS(a)
#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE
#define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE
uint8_t packet_buf[PACKET_SIZE]
#define ASF_PPI_PROPERTY_FLAGS
enum AVMediaType codec_type
const ff_asf_guid ff_asf_file_header
#define SINGLE_PAYLOAD_DATA_LENGTH
AVIOContext * pb
I/O context.
const ff_asf_guid ff_asf_video_stream
int64_t packet_timestamp_end
void avio_w8(AVIOContext *s, int b)
main external API structure.
uint16_t stream_language_index
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
static void flush_packet(AVFormatContext *s)
rational number numerator/denominator
void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf, int ignore_extradata)
const ff_asf_guid ff_asf_stream_header
static const AVCodecTag codec_asf_bmp_tags[]
int avio_put_str16le(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16LE and write it.
const AVMetadataConv ff_asf_metadata_conv[]
const char * name
Name of the codec described by this descriptor.
static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g)
int64_t duration
in 100ns units
This struct describes the properties of a single codec described by an AVCodecID. ...
#define ASF_INDEXED_INTERVAL
const ff_asf_guid ff_asf_comment_header
static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst, int64_t timestamp, const uint8_t *buf, int m_obj_size, int flags)
static int64_t pts
Global timestamp for the audio frames.
#define MULTI_PAYLOAD_CONSTANT
static void end_header(AVIOContext *pb, int64_t pos)
#define ASF_PL_FLAG_KEY_FRAME
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
uint64_t nb_packets
how many packets are there in the file, invalid if broadcasting
const ff_asf_guid ff_asf_audio_conceal_spread
const ff_asf_guid ff_asf_codec_comment1_header
AVRational time_base
time base in which the start/end timestamps are specified
static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc, int flags)
Write WAVEFORMAT header structure.
void * priv_data
Format private data.
uint32_t nb_index_memory_alloc
static void write_header(FFV1Context *f)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static int asf_write_stream_header(AVFormatContext *s)
static void put_str16(AVIOContext *s, const char *tag)
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
#define PACKET_HEADER_MIN_SIZE
const ff_asf_guid ff_asf_marker_header
static int update_index(AVFormatContext *s, int start_sec, uint32_t packet_number, uint16_t packet_count, uint64_t packet_offset)
unsigned char multi_payloads_present
#define MKTAG(a, b, c, d)
This structure stores compressed data.
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
uint64_t next_packet_offset
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX
Tell ff_put_wav_header() to use WAVEFORMATEX even for PCM codecs.